mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
chore(deps): bump express from 4.22.3 to 5.3.0 and @types/express to 5.0.6
Nest already serves every request through Express 5. Only the parsers, the static handler and their types still came from the direct Express 4 dependency, so this moves those three and keeps their behaviour: - body-parser 2 leaves req.body undefined when it did not read a body, where body-parser 1 left an empty object. A bodyless POST to a route whose fields are all optional answered 400, and a plugin route got null. emptyBodyDefault restores the empty object for everything but /mcp, which stays raw (BOOT-009, PACK-3T-004). - serve-static 2 no longer exposes its mime table. The Brotli copy of an asset is typed through mime-types 3 with the fallback send uses, so it keeps the Content-Type of the original file (PRECOMP-001). - @types/express 5 types a route param as string or string[]; the photo route names its single :filename param. The MCP SDK resolves the same Express 5.3 now; Nest keeps the 5.2.1 it pins.
This commit is contained in:
Generated
+377
-741
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -93,7 +93,7 @@
|
||||
"cron": "^4.4.0",
|
||||
"dotenv": "^18.0.10",
|
||||
"exifr": "7.1.3",
|
||||
"express": "^4.22.3",
|
||||
"express": "^5.3.0",
|
||||
"fast-xml-parser": "^5.12.1",
|
||||
"helmet": "^8.3.0",
|
||||
"imapflow": "^1.0.0",
|
||||
@@ -101,6 +101,7 @@
|
||||
"json5": "^2.2.3",
|
||||
"jsonwebtoken": "^9.0.3",
|
||||
"kysely": "^0.29.6",
|
||||
"mime-types": "^3.0.2",
|
||||
"multer": "^2.5.0",
|
||||
"nestjs-zod": "^5.6.0",
|
||||
"nodemailer": "^10.6.1",
|
||||
@@ -134,8 +135,9 @@
|
||||
"@types/compression": "^1.8.1",
|
||||
"@types/cookie-parser": "^1.4.10",
|
||||
"@types/cors": "^2.8.19",
|
||||
"@types/express": "^4.17.25",
|
||||
"@types/express": "^5.0.6",
|
||||
"@types/jsonwebtoken": "^9.0.10",
|
||||
"@types/mime-types": "^3.0.1",
|
||||
"@types/multer": "^2.3.0",
|
||||
"@types/node": "^26.6.11",
|
||||
"@types/nodemailer": "^8.0.2",
|
||||
|
||||
@@ -232,6 +232,14 @@ export async function buildApp(): Promise<INestApplication> {
|
||||
instance.use(function urlencodedParser(req: Request, res: Response, next: NextFunction) {
|
||||
return isMcp(req) ? next() : urlencoded(req, res, next);
|
||||
});
|
||||
// A request the parsers above did not read (no body, or another content type)
|
||||
// keeps an empty object as its body, as it always had: body-parser 2 leaves
|
||||
// it undefined, which a route whose fields are all optional would refuse and a
|
||||
// plugin route would receive as null. /mcp stays raw.
|
||||
instance.use(function emptyBodyDefault(req: Request, _res: Response, next: NextFunction) {
|
||||
if (req.body === undefined && !isMcp(req)) req.body = {};
|
||||
next();
|
||||
});
|
||||
// Every request value without NUL from here on (nest/common/nul-free-input.ts):
|
||||
// the path, the query string, the parsed body and the cookies, before any
|
||||
// guard, interceptor or controller reads them, so a key or a check made from
|
||||
|
||||
@@ -155,7 +155,7 @@ async function resolveServedName(name: string, serving: PublicServing | undefine
|
||||
|
||||
async function servePhoto(
|
||||
storage: StorageService,
|
||||
req: Request,
|
||||
req: Request<{ filename: string }>,
|
||||
res: Response,
|
||||
users: UsersRepository,
|
||||
shareTokens: ShareTokensRepository,
|
||||
@@ -314,7 +314,7 @@ export function applyPlatformUploads(
|
||||
// photo's trip. Previously any share token for any trip could request
|
||||
// any photo filename by UUID — fine in practice because UUIDs are
|
||||
// unguessable, but the auth model was wrong.
|
||||
app.get('/uploads/photos/:filename', (req: Request, res: Response, next: NextFunction) => {
|
||||
app.get('/uploads/photos/:filename', (req: Request<{ filename: string }>, res: Response, next: NextFunction) => {
|
||||
if (!orm) {
|
||||
next(new Error('applyPlatformUploads: no MikroORM available to build a request context for /uploads/photos/*'));
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import express, { type NextFunction, type Request, type Response } from 'express';
|
||||
import type { NextFunction, Request, Response } from 'express';
|
||||
import { contentType } from 'mime-types';
|
||||
import { readdirSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
@@ -19,12 +20,9 @@ function collectPrecompressed(dir: string, urlPrefix: string, into: Set<string>)
|
||||
return into;
|
||||
}
|
||||
|
||||
/** The Content-Type the static handler gives the original file, charset included, from the same table. */
|
||||
/** The Content-Type the static handler (send) gives the original file, from the same table and with the same fallback. */
|
||||
function contentTypeOf(file: string): string {
|
||||
const { mime } = express.static;
|
||||
const type = mime.lookup(file);
|
||||
const charset = mime.charsets.lookup(type, '');
|
||||
return charset ? `${type}; charset=${charset}` : type;
|
||||
return contentType(path.extname(file)) || 'application/octet-stream';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -132,6 +132,24 @@ describe('BOOTSTRAP (F6) — unified NestJS app serves the whole surface', () =>
|
||||
expect(res.body.type).toBe('FeatureCollection');
|
||||
});
|
||||
|
||||
it('BOOT-009 — a request without a parsed body gets an empty object, except /mcp, which stays raw', async () => {
|
||||
type Layer = { name: string; handle: (req: object, res: object, next: () => void) => void };
|
||||
const { stack } = (instance as unknown as { router: { stack: Layer[] } }).router;
|
||||
const names = stack.map((layer) => layer.name);
|
||||
expect(names.indexOf('emptyBodyDefault')).toBeGreaterThan(names.indexOf('urlencodedParser'));
|
||||
const emptyBodyDefault = stack[names.indexOf('emptyBodyDefault')].handle;
|
||||
const run = (path: string, body?: unknown) =>
|
||||
new Promise<unknown>((resolve) => {
|
||||
const req = { path, body };
|
||||
emptyBodyDefault(req, {}, () => resolve(req.body));
|
||||
});
|
||||
|
||||
expect(await run('/api/trips/1/packing/2/contributors')).toEqual({});
|
||||
expect(await run('/api/trips', { name: 'kept' })).toEqual({ name: 'kept' });
|
||||
expect(await run('/mcp')).toBeUndefined();
|
||||
expect(await run('/mcp/')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('BOOTSTRAP-ORM-001: the ORM unit of work resolves from the container', () => {
|
||||
expect(app.get(UnitOfWork)).toBeInstanceOf(UnitOfWork);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user