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

default discord avatar
JasmineP
8 months ago
2

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 🥸

  • default discord avatar
    Martin R
    8 months ago

    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();
        },
      ],
  • discord user avatar
    jmikrut
    Payload Team
    8 months ago

    hmm, i have no clue why that's typed as any but yeah it should be an array of Express middleware that gets added

    after

    the Payload middleware is added

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.