Hi! Still learning about everything that goes into the config file, but noticed there's no documentation regarding how the
postMiddlewarearray is supposed to work inside the
expressobject in the config file. Seems to be typed as
anyas 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 dedicated engineering support directly from the Payload team.