API
init()
Registers all known routes with @xpulse/http.
register(method, path, handler, name = null, namePrefix = null, pathPrefix = null)
1 router.register ('GET' , '/info' , handler); 2 router.register ('GET' , '/info/:page?' , handler);
Optional with default params (legacy signature):
1 router.register ('GET' , '/tool/:tool/:page?' , handler, { tool : 'chat' , page : 'guide' });
Compatibility note:
If the 4th argument is an object and namePrefix/pathPrefix are not provided,
it is treated as legacy defaults. For named/prefixed routes, use the new signature.
Optional with name and prefixes:
1 router.register ('GET' , '/info' , handler, 'info.index' , 'app' , null ); 2 router.register ('GET' , '/web-profiler/:traceId/dashboard/' , handler, 'web-profiler.traceId.dashboard' , 'debug' , '/_debug' );
Prefixes
By default, auto-generated route names start with app. and do not include the HTTP method.
You can override the default prefixes via xpulse.json:
1 { 2 "router" : { 3 "name-prefix" : "app" , 4 "path-prefix" : "" 5 } 6 }
You can also set prefixes per package via register(...):
1 router.register ('GET' , '/web-profiler/:traceId/dashboard/' , handler, 'web-profiler.traceId.dashboard' , 'debug' , '/_debug' );
notFound(handler)
1 router.notFound ((req, res ) => { 2 res.status (404 ).send ('Not found' ); 3 });
getPath(pattern, params)
1 const path = router.getPath ('/tool/:tool/:page?' , { tool : 'chat' });2
list()
1 const routes = router.list ();2 3 4
Events
router:matched β emitted when a route is matched payload: { method, path, params, name, traceId }