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