onReady method
Initializes built-in Jetleaf routes.
This method is automatically invoked before the Pod is fully constructed
(via @PreConstruct) to register core framework endpoints.
Example:
mapping.init();
The default route:
GET /jetleaf → resources/framework/home.html
Implementation
@override
@mustCallSuper
Future<void> onReady() async {
final routerBuilder = RouterBuilder()
..route(GET("/jetleaf"), (req) => PageView("jetleaf_web/resources/framework/home.html", HttpStatus.OK)
..addAttribute("FAVICON", Constant.FAVICON)
..addAttribute("ICON", Constant.ICON)
)
..routeX(GET('/favicon.ico'), (req, res) async {
const svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
'<text y=".9em" font-size="90">${Constant.ICON}</text></svg>';
res.getHeaders().setContentType(MediaType.parse('image/svg+xml; charset=utf-8'));
res.setStatus(HttpStatus.OK);
return tryWith(res.getBody(), (output) async => await output.writeString(svg, Closeable.DEFAULT_ENCODING));
})
..ignoreContextPath = true;
final spec = routerBuilder.build(contextPath: getContextPath());
final definitions = spec.routes;
for (final definition in definitions) {
registerHandler(
parser.getParser().parsePattern(definition.path),
FrameworkHandlerMethod(DefaultHandlerArgumentContext(), definition),
);
}
return super.onReady();
}