multipart

This commit is contained in:
seb
2026-09-18 07:19:20 +02:00
parent 8c19388901
commit c2147de284
9 changed files with 224 additions and 47 deletions

View File

@@ -65,7 +65,7 @@ async function createApi() {
next();
});
app.use(corsMiddleware);
app.use(express.json());
app.use(express.json({ limit: env.bodyLimit }));
app.use(cookieParser());
app.use(loggerMiddleware);
app.use(authMiddleware);
@@ -79,6 +79,16 @@ async function createApi() {
await loadRoutes(app, '/api');
app.use((err, _req, res, next) => {
if (err.type === 'entity.too.large') {
return res.status(413).json({ error: 'Payload too large' });
}
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
return res.status(400).json({ error: 'Invalid JSON body' });
}
next(err);
});
return app;
}