#Documentation regarding "postMiddleware" for the express config in payload.config.ts

2 messages · Page 1 of 1 (latest)

flat rose
#

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 🥸

spring tangle
#

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();
    },
  ],