diff --git a/app.js b/app.js index e1275be..66e7fb4 100644 --- a/app.js +++ b/app.js @@ -5,6 +5,7 @@ const cookieParser = require('cookie-parser') const logger = require('morgan') const passport = require('passport') const session = require('express-session') +const cors = require('cors') const app = express() @@ -29,15 +30,7 @@ app.use(express.urlencoded({ extended: false })) app.use(cookieParser()) app.use(express.static(path.join(__dirname, 'public'))) -app.use('/', - function (req, res, next) { - res.setHeader('Access-Control-Allow-Origin', '*') - res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE') - res.setHeader('Access-Control-Allow-Credentials', true) - res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, cache-control, pragma, If-Modified-Since') - - next() - }) +app.use(cors()) app.use('/', require('./routes/vegetableTypes')(passport)) app.use('/', require('./routes/vegetables')(passport)) diff --git a/package-lock.json b/package-lock.json index 8ebae44..a4fdfa8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1288,6 +1288,15 @@ "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, + "cors": { + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz", + "integrity": "sha1-K9OB8usgECAQXNUOpZ2mMJBpRoY=", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "crc": { "version": "3.4.4", "resolved": "https://registry.npmjs.org/crc/-/crc-3.4.4.tgz", diff --git a/package.json b/package.json index 72a3eec..d1db477 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "aws-sdk": "^2.311.0", "bcrypt-nodejs": "0.0.3", "cookie-parser": "~1.4.3", + "cors": "^2.8.4", "debug": "~2.6.9", "express": "~4.16.0", "express-session": "^1.15.6",