From a91e96d6d1ca00bb97eca1df55de01ec313500a8 Mon Sep 17 00:00:00 2001 From: Brainslug Date: Tue, 30 Aug 2022 16:11:45 +0200 Subject: [PATCH] Moved CORS headers before the JSON body is parsed (#15308) --- api/src/app.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/api/src/app.ts b/api/src/app.ts index d98c6c7071..76075247da 100644 --- a/api/src/app.ts +++ b/api/src/app.ts @@ -137,6 +137,15 @@ export default async function createApp(): Promise { app.use(expressLogger); + app.use((_req, res, next) => { + res.setHeader('X-Powered-By', 'Directus'); + next(); + }); + + if (env.CORS_ENABLED === true) { + app.use(cors); + } + app.use((req, res, next) => { ( express.json({ @@ -155,15 +164,6 @@ export default async function createApp(): Promise { app.use(extractToken); - app.use((_req, res, next) => { - res.setHeader('X-Powered-By', 'Directus'); - next(); - }); - - if (env.CORS_ENABLED === true) { - app.use(cors); - } - app.get('/', (_req, res, next) => { if (env.ROOT_REDIRECT) { res.redirect(env.ROOT_REDIRECT);