mirror of
https://github.com/KevinMidboe/leifsbackend.git
synced 2025-10-29 17:50:20 +00:00
Pulled the origin out in a variable.
This commit is contained in:
10
src/app.js
10
src/app.js
@@ -3,26 +3,28 @@ const logger = require('morgan')
|
|||||||
const bodyParser = require('body-parser')
|
const bodyParser = require('body-parser')
|
||||||
|
|
||||||
const routes = require('./routes')
|
const routes = require('./routes')
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(logger('dev'));
|
app.use(logger('dev'));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.urlencoded({ extended: false }));
|
app.use(bodyParser.urlencoded({ extended: false }));
|
||||||
routes(app)
|
|
||||||
|
const ORIGIN = 'http://localhost:8080';
|
||||||
|
|
||||||
app.options("/*", function(req, res, next){
|
app.options("/*", function(req, res, next){
|
||||||
res.header('Access-Control-Allow-Origin', 'http://localhost:8080');
|
res.header('Access-Control-Allow-Origin', ORIGIN);
|
||||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
||||||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
|
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.all('/*', function(req, res, next) {
|
app.all('/*', function(req, res, next) {
|
||||||
res.header('Access-Control-Allow-Origin', 'http://localhost:8080')
|
res.header('Access-Control-Allow-Origin', ORIGIN)
|
||||||
next();
|
next();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
routes(app)
|
||||||
|
|
||||||
app.get('*', (req, res) => res.status(200).send({
|
app.get('*', (req, res) => res.status(200).send({
|
||||||
message: 'Welcome to the beginning of nothingness',
|
message: 'Welcome to the beginning of nothingness',
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user