Reputation: 5125
I'm trying to serve static content for a facebook app using express.js
app.configure(function (){
app.use('/', express.static(__dirname + '/public'));
});
This works on a GET
however on a POST
I get a 404
saying Cannot POST /
curl -X POST localhost:3001
Cannot POST /
How can I get around this?
Based on zerkms's answer I came up with this hack, which I imagine is quite bad practice.
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'));
});
This works but I'd still like a better solution if anyone has one.
Upvotes: 3
Views: 692
Reputation: 254944
It only serves GET
or HEAD
requests.
See https://github.com/expressjs/serve-static/blob/master/index.js#L51
if ('GET' != req.method && 'HEAD' != req.method) return next();
Upvotes: 2