Pulled the origin out in a variable.

This commit is contained in:
2019-03-03 22:06:50 +01:00
parent f5b6d0f426
commit c7cd82af5f

View File

@@ -3,26 +3,28 @@ const logger = require('morgan')
const bodyParser = require('body-parser')
const routes = require('./routes')
const app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
routes(app)
const ORIGIN = 'http://localhost:8080';
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-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
res.send(200);
});
app.all('/*', function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:8080')
res.header('Access-Control-Allow-Origin', ORIGIN)
next();
})
routes(app)
app.get('*', (req, res) => res.status(200).send({
message: 'Welcome to the beginning of nothingness',
}));