使用express.js在POST上提供静态内容
我正在尝试使用express.js
为Facebook应用程序提供静态内容
app.configure(function (){ app.use('/', express.static(__dirname + '/public')); });
这工作在一个GET
但是在一个POST
我得到一个404
说Cannot POST /
curl -X POST localhost:3001 Cannot POST /
我怎样才能解决这个问题?
基于zerkms的答案,我想出了这个黑客,我认为这是一个很糟糕的做法。
app.post('/', function(req, res, next){ try { if(req.url === '/'){ req.method = 'GET' } } catch(err){ res.send(500, err) res.end() } next() }); app.configure(function (){ app.use('/', express.static(__dirname + '/public')); });
这工作,但我仍然喜欢一个更好的解决scheme,如果任何人有一个。
它只提供GET
或HEAD
请求。
请参阅https://github.com/expressjs/serve-static/blob/master/index.js#L51
if ('GET' != req.method && 'HEAD' != req.method) return next();