For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /configure/app/dev/setup-middlewares.md.

dev.setupMiddlewares

  • Type:
type RequestHandler = (req: any, res: any, next: () => void) => void;

type ExposeServerApis = {
  sockWrite: (
    type: string,
    data?: string | boolean | Record<string, any>,
  ) => void;
};

type SetupMiddlewares = Array<
  (
    middlewares: {
      unshift: (...handlers: RequestHandler[]) => void;
      push: (...handlers: RequestHandler[]) => void;
    },
    server: ExposeServerApis,
  ) => void
>;
  • Default: undefined

Provides the ability to execute a custom function and apply custom middlewares.

Info

The usage of this configuration item is exactly the same as that of Rsbuild. For detailed information, please refer to Rsbuild - dev.setupMiddlewares.