mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +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:
@@ -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';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user