refactor(core): Load cookieParser middleware only once (no-changelog) (#6614)

[Server.ts already explicitly loads `cookieParser`](https://github.com/n8n-io/n8n/blob/master/packages/cli/src/Server.ts#L571)
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-07-07 09:57:03 +02:00 committed by GitHub
parent 7383e7fd48
commit a76223307f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 3 deletions

View file

@ -1,6 +1,5 @@
import type { Application, NextFunction, Request, RequestHandler, Response } from 'express'; import type { Application, NextFunction, Request, RequestHandler, Response } from 'express';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import cookieParser from 'cookie-parser';
import passport from 'passport'; import passport from 'passport';
import { Strategy } from 'passport-jwt'; import { Strategy } from 'passport-jwt';
import { sync as globSync } from 'fast-glob'; import { sync as globSync } from 'fast-glob';
@ -78,8 +77,6 @@ export const setupAuthMiddlewares = (
ignoredEndpoints: Readonly<string[]>, ignoredEndpoints: Readonly<string[]>,
restEndpoint: string, restEndpoint: string,
) => { ) => {
// needed for testing; not adding overhead since it directly returns if req.cookies exists
app.use(cookieParser());
app.use(userManagementJwtAuth()); app.use(userManagementJwtAuth());
app.use(async (req: Request, res: Response, next: NextFunction) => { app.use(async (req: Request, res: Response, next: NextFunction) => {

View file

@ -2,6 +2,7 @@ import { Container } from 'typedi';
import { randomBytes } from 'crypto'; import { randomBytes } from 'crypto';
import { existsSync } from 'fs'; import { existsSync } from 'fs';
import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser'; import bodyParser from 'body-parser';
import { CronJob } from 'cron'; import { CronJob } from 'cron';
import express from 'express'; import express from 'express';
@ -121,6 +122,7 @@ export async function initTestServer({
testServer.app.use(bodyParser.json()); testServer.app.use(bodyParser.json());
testServer.app.use(bodyParser.urlencoded({ extended: true })); testServer.app.use(bodyParser.urlencoded({ extended: true }));
testServer.app.use(cookieParser());
config.set('userManagement.jwtSecret', 'My JWT secret'); config.set('userManagement.jwtSecret', 'My JWT secret');
config.set('userManagement.isInstanceOwnerSetUp', false); config.set('userManagement.isInstanceOwnerSetUp', false);