From 74858cc22f1c6a33409cc7034cb9a751e4478cc4 Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Thu, 23 Oct 2014 11:26:58 -0500 Subject: [PATCH 1/3] Added cors middleware --- lib/application.js | 4 +++- package.json | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/application.js b/lib/application.js index 9a42e63..2b07db3 100644 --- a/lib/application.js +++ b/lib/application.js @@ -19,6 +19,7 @@ var async = require('async'); var lodash = require('lodash'); var utils = Prana.utils; var Storage = require('./storage'); +var cors = require('cors'); // Patch Prana. require('./prana-patch'); @@ -60,7 +61,8 @@ var Application = module.exports = function(mainApplication, hostname, settings) multer(), methodOverride(), // @todo: move cookieParser to session extension? - cookieParser() + cookieParser(), + cors() ]; // Add middlewares to rest and page routers. diff --git a/package.json b/package.json index 7c16e7a..eb8fdd9 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "validator": "2.0.x", "mkdirp": "0.3.x", "node-uuid": "1.4.x", - "lodash": "2.x.x" + "lodash": "2.x.x", + "cors": "^2.4.1" }, "devDependencies": { "mocha": "*", From ed01dd806efcc0c07594668a36f3dce1fe02c5de Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Wed, 29 Jul 2015 20:52:49 -0500 Subject: [PATCH 2/3] Added optional configuration to use cors middleware. --- lib/application.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/application.js b/lib/application.js index bad1adc..59a2d1e 100644 --- a/lib/application.js +++ b/lib/application.js @@ -70,10 +70,21 @@ var Application = module.exports = function(settings) { multer(), methodOverride(), // @todo: move cookieParser to session extension? - cookieParser(), - cors() + cookieParser() ]; + // Settings cors middleware. + if (this.settings && this.settings.cors) { + var options = {}; + + if (typeof this.settings.cors === 'boolean') { + middlewares.push(cors()); + } + else if (typeof this.settings.cors === 'object') { + middlewares.push(cors(this.settings.cors)); + } + } + // Add middlewares to rest and page routers. middlewares.forEach(function(middleware) { ['rest', 'page'].map(function(routerName) { From 62cbde2a044543fac3f39cd4a6513102ee017d09 Mon Sep 17 00:00:00 2001 From: Joseph Ramos Date: Fri, 31 Jul 2015 12:37:10 -0500 Subject: [PATCH 3/3] Refactoring cors configurations. --- lib/application.js | 11 ++--------- package.json | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/application.js b/lib/application.js index 59a2d1e..a561d04 100644 --- a/lib/application.js +++ b/lib/application.js @@ -74,15 +74,8 @@ var Application = module.exports = function(settings) { ]; // Settings cors middleware. - if (this.settings && this.settings.cors) { - var options = {}; - - if (typeof this.settings.cors === 'boolean') { - middlewares.push(cors()); - } - else if (typeof this.settings.cors === 'object') { - middlewares.push(cors(this.settings.cors)); - } + if (this.settings.cors && this.settings.cors.enabled) { + middlewares.push(cors(this.settings.cors)); } // Add middlewares to rest and page routers. diff --git a/package.json b/package.json index 0b8a009..62a4ea1 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "node-uuid": "1.4.x", "passport": "0.1.x", "passport-anonymous": "1.0.x", - "cors": "^2.4.1", + "cors": "2.4.1", "passport-http": "0.2.x", "passport-local": "0.1.x", "path-to-regexp": "0.1.x",