feat: move up and enable cors

This commit is contained in:
Michel Jonathan Schmitz
2020-05-07 16:36:55 +02:00
committed by Rainer Killinger
parent c61c37dc27
commit 6483221b62

View File

@@ -47,6 +47,30 @@ export async function configureApp(app: Express) {
// request loggers have to be the first middleware to be set in express
app.use(morgan('dev'));
const corsOptions = {
allowedHeaders: [
'DNT',
'Keep-Alive',
'User-Agent',
'X-Requested-With',
'If-Modified-Since',
'Cache-Control',
'Content-Type',
'X-StApps-Version',
],
credentials: true,
maxAge: 1728000,
methods: ['GET', 'POST', 'PUT', 'OPTIONS'],
optionsSuccessStatus: 204,
};
// allow all origins on all routes
app.use(cors(corsOptions));
// TODO: See if it can handle options request with no content-type
// allow cors preflight requests on every route
app.options('*', cors(corsOptions));
// only accept json as content type for all requests
app.use((req, res, next) => {
// get the content type
@@ -158,30 +182,6 @@ export async function configureApp(app: Express) {
app.set('env', process.env.NODE_ENV);
const corsOptions = {
allowedHeaders: [
'DNT',
'Keep-Alive',
'User-Agent',
'X-Requested-With',
'If-Modified-Since',
'Cache-Control',
'Content-Type',
'X-StApps-Version',
],
credentials: true,
maxAge: 1728000,
methods: ['GET', 'POST', 'PUT', 'OPTIONS'],
optionsSuccessStatus: 204,
};
// allow all origins on all routes
app.use(cors(corsOptions));
// TODO: See if it can handle options request with no content-type
// allow cors preflight requests on every route
app.options('*', cors(corsOptions));
// load routes before plugins
// they now can be used or overwritten by any plugin
app.use(