I am working on a node.js project and I need to do a connection with facebook.
I picked some facebook libraries. The last one that I liked was facebook-wrapper. Their example works perfect, but when I add express.static(__dirname + '/public')
, I get an error: Cannot POST /
. I tried with connect too, but I have the same error.
var server = express.createServer(
express.logger(),
express.bodyParser(),
express.cookieParser(),
express.session({ secret: 'secret123' }),
facebook.auth(options),
express.static(__dirname + '/public')
);
The problem is that the static middleware doesn't serve requests coming with POST method. You have to handle it in router explicitly, like this:
app.post('/', function(req, res) {
res.sendfile(__dirname + '/public/index.html');
});
However there is a pull request to ease this: https://github.com/senchalabs/connect/pull/482.
Order of arguments matters for Connet and Express. Rearrange the arguments. Try putting 'facebook.auth(options)' as last argument.