index: respond 204 to OPTIONS requests
This commit is contained in:
parent
ce7de0b63c
commit
77211dbaf7
14
lib/index.js
14
lib/index.js
@ -140,9 +140,19 @@ InsightAPI.prototype.setupRoutes = function(app) {
|
|||||||
|
|
||||||
//Enable CORS
|
//Enable CORS
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
|
|
||||||
res.header('Access-Control-Allow-Origin', '*');
|
res.header('Access-Control-Allow-Origin', '*');
|
||||||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
|
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, OPTIONS');
|
||||||
next();
|
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
|
//Block routes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user