> For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt.

# dev.setupMiddlewares

- **类型：**

```ts
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
>;
```

- **默认值：** `undefined`

提供执行自定义函数和应用自定义中间件的能力。

:::info
该配置项的使用方式与 Rsbuild 完全一致。详细信息请参考 [Rsbuild - dev.setupMiddlewares](https://v2.rsbuild.dev/zh/config/dev/setup-middlewares)。
:::