configure simple CORS

This commit is contained in:
Sorrel Bri 2020-01-07 13:30:19 -08:00 committed by sorrelbri
parent b2d9eaca0d
commit ea878c9057
3 changed files with 32 additions and 12 deletions

View file

@ -229,6 +229,15 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
}, },
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"debug": { "debug": {
"version": "2.6.9", "version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@ -579,6 +588,11 @@
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
}, },
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"object-component": { "object-component": {
"version": "0.0.3", "version": "0.0.3",
"resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz",

View file

@ -9,6 +9,7 @@
"chai": "^4.2.0", "chai": "^4.2.0",
"chai-http": "^4.3.0", "chai-http": "^4.3.0",
"cookie-parser": "~1.4.4", "cookie-parser": "~1.4.4",
"cors": "^2.8.5",
"debug": "~2.6.9", "debug": "~2.6.9",
"express": "~4.16.1", "express": "~4.16.1",
"http-errors": "~1.6.3", "http-errors": "~1.6.3",

View file

@ -1,17 +1,22 @@
var createError = require('http-errors'); const createError = require('http-errors');
var express = require('express'); const express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index'); const cors = require('cors');
var usersRouter = require('./routes/users'); const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
var app = express(); const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
// view engine setup const app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade'); const corsOptions = {
origin: '*'
}
app.options('*', cors(corsOptions));
app.use('*', cors(corsOptions));
app.use(logger('dev')); app.use(logger('dev'));
app.use(express.json()); app.use(express.json());
@ -35,7 +40,7 @@ app.use(function(err, req, res, next) {
// render the error page // render the error page
res.status(err.status || 500); res.status(err.status || 500);
res.render('error'); res.send('error');
}); });
module.exports = app; module.exports = app;