Pages
Contents
API
init()
| await controller.init(); |
Discovers controllers and registers routes with @xpulse/router.
Naming scheme:
app.<controller>.<method>for app-root controllers (rootDir = process.cwd()).<package>.<controller>.<method>for package controllers (from/node_modules/@xpulse/*).
You can override the prefix:
| await controller.init({ root: '/path/to/package', prefix: 'debug' }); |
Controller Base Class
| import { Controller } from '@xpulse/controller'; |
Response helpers:
this.render(view, data)this.response(html, options)this.json(data, options)this.redirect(url)
render() uses @xpulse/template if installed. If not present, it logs a warning
and returns the provided string unchanged.
Trace ID
If req.traceId is present, render() forwards it into the template data as _traceId.
Events
| Event | Payload | When |
|---|---|---|
controller:init |
{ root } |
Discovery begins |
controller:discovered |
{ name, routes } |
Controller found |
controller:ready |
{ count, routes } |
All registered |
controller:called |
{ traceId, controller, action, method, path, name } |
Handler called |
controller:navigation:collected |
{ items } |
Navigation items collected |
controller:navigation:ready |
{ items } |
Navigation ready |