I have an express.js application with a setup for cross-domain
var allowedHost = {
'http://localhost:3001': true,
'http://localhost:7357': true
};
var allowCrossDomain = function(req, res, next) {
if(allowedHost[req.headers.origin]) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', req.headers.origin)
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version');
next();
} else {
res.send(403, {auth: false});
}
}
my client (backbone.js) is configured to accept cross domain as well and everything is working fine for this part..
now, inside my express.js app (running on port 3001) i'm trying to access simple pages like so :
app.get('/app', function(req, res, next){
return res.render("" + __dirname + "/views/app", {
title: 'hello world'
});
});
if i call the url localhost:3001/app for example i have 403 error because the req.headers.origin is undefined, Do you have any idea ?
How should i tell my normal express.js routes to cope with the cross domain checking ?
Any help on this issue will be really appreciated ;-)