Merge pull request #481 from braydonf/cors
index: respond 204 to OPTIONS requests
This commit is contained in:
commit
ef85ba4a08
14
lib/index.js
14
lib/index.js
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user