Hi! Still learning about everything that goes into the config file, but noticed there's no documentation regarding how the
postMiddleware
array is supposed to work inside the
express
object in the config file. Seems to be typed as
any
as well 🥸
I don't know if postMiddleware is stable, and it apparently only works for API routes
import { PayloadRequest } from "payload/types";
import { NextFunction, Response } from "express";
preMiddleware: [
...(config.express?.preMiddleware || []),
(req: PayloadRequest, res: Response, next: NextFunction) => {
console.log(req.path, req.user); // preMiddleware User is undefined
next();
},
],
postMiddleware: [
...(config.express?.postMiddleware || []),
(req: PayloadRequest, res: Response, next: NextFunction) => {
console.log(req.path, req.user); // postMiddleware User is defined
next();
},
],
hmm, i have no clue why that's typed as any but yeah it should be an array of Express middleware that gets added
afterthe Payload middleware is added
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.