Moved CORS headers before the JSON body is parsed (#15308)

This commit is contained in:
Brainslug
2022-08-30 16:11:45 +02:00
committed by GitHub
parent f77d12eff4
commit a91e96d6d1

View File

@@ -137,6 +137,15 @@ export default async function createApp(): Promise<express.Application> {
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<express.Application> {
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);