Used to extend Modern.js built-in Web Server, all page requests are handled by these hooks.
It is recommended to use UnstableMiddleware to handle page requests.
For more detail, see Extend Web Server.
Before using this API, please execute pnpm run new
to create a new "Custom Web Server" source code directory.
different Hooks additionally provide different contexts. Currently Modern.js support AfterMatch
and AfterRender
.
context
: Hook context.
response
: provides a series of methods to process the response.request
: provides a series of methods to get request info.router
: provides methods on routing.template
: provides methods on content.next
: call next listener (not affect the server process, only current hook).Redirect to pages outside the site, for example to login page:
Rewrite to pages of the current site, for example, the same route returns pages that are adapted to different UA:
Inject some HTML content to the page, such as scripts, page skeletons, etc.: