index: respond 204 to OPTIONS requests

This commit is contained in:
Braydon Fuller 2016-05-31 11:49:09 -04:00
parent ce7de0b63c
commit 77211dbaf7

View File

@ -140,9 +140,19 @@ InsightAPI.prototype.setupRoutes = function(app) {
//Enable CORS
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Content-Length, Cache-Control, cf-connecting-ip');
var method = req.method && req.method.toUpperCase && req.method.toUpperCase();
if (method === 'OPTIONS') {
res.statusCode = 204;
res.end();
} else {
next();
}
});
//Block routes