Skip to content
On this page

Middlewares

Usage

ts
import { Middleware } from 'prext';

export const Message: Middleware = (req, res, next) => {
  (req as any).message = 'Hello World!';
  next();
};
ts
import { PrextRequest, PrextResponse } from 'prext';

export function get(req: PrextRequest, res: PrextResponse) {
  res.end((req as any).message);
}

Regists

Add them to config.middlewares.

ts
import { Message } from './middlewares/message';

export default defineConfig({
  middlewares: [Message],
  // ...
});

Auto Mode

WARNING

autoMiddlewareMode is a experimental feature.

To use auto middleware mode, edit config value.

ts
import { Middleware } from 'prext';

const Message: Middleware = (req, res, next) => {
  (req as any).message = 'Hello World!';

  next();
};

// export as default

export default Message;
ts
export default defineConfig({
  allowAutoMiddlewares: true,
  middlewareDirectory: 'middlewares',
});