Middleware has been deprecated. Please use the new Custom Web Server to handle page requests.
Used to extend the built-in Web Server of Modern.js, unlike Hook, Middleware can directly operate Node's origin request and response, and can be extended using the framework plugin.
Before using this API, please execute pnpm run new
to create a new "Custom Web Server" source code directory.
context
: Middleware context.
response
: provides a series of methods to process the response.request
: provides a series of methods to get request info.source
: provides Node.js native req
and res
object.next
: call next listener (not affect the server process, only current hook).
The execution of the next
function does not affect built-in processes, only controls whether the next middleware executes. Rendering processes are interrupted only when the response is written.
Modern.js provides res.locals
to store local variables for the current request.