From 77211dbaf7b4d90bef3030f03eb19d0d1cbc252e Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Tue, 31 May 2016 11:49:09 -0400 Subject: [PATCH] index: respond 204 to OPTIONS requests --- lib/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 08e0843..189ff36 100644 --- a/lib/index.js +++ b/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