Routes
Put your route handlers into the /routes
directory of your Jova application.
Route Handler Boilerplates
// ESM
// ./routes/Route.ts
import {
ApplicationRegistry,
ApplicationRequest,
ApplicationResponse,
ApplicationRoute,
Methods,
RouteController,
} from '@bracketed/jova.js/types';
export class Route extends RouteController {
public override registerApplicationRoutes(registry: ApplicationRegistry): ApplicationRoute {
return registry.registerApplicationRoutes((route) =>
route //
.setRouteName('')
.setMethod(Methods.GET)
);
}
public override async run(
request: ApplicationRequest,
response: ApplicationResponse
): Promise<ApplicationResponse | void> {
this.logger.info('Recieved request for', request.baseUrl);
return response.status(200).json({ message: 'Hello World!' });
}
}
// CJS
// ./routes/Route.ts
const {
ApplicationRegistry,
ApplicationRequest,
ApplicationResponse,
ApplicationRoute,
Methods,
RouteController,
} = require('@bracketed/jova.js/types');
export class Route extends RouteController {
public override registerApplicationRoutes(registry: ApplicationRegistry): ApplicationRoute {
return registry.registerApplicationRoutes((route) =>
route //
.setRouteName('')
.setMethod(Methods.GET)
);
}
public override async run(
request: ApplicationRequest,
response: ApplicationResponse
): Promise<ApplicationResponse | void> {
this.logger.info('Recieved request for', request.baseUrl);
return response.status(200).json({ message: 'Hello World!' });
}
}