fix: leading backslash on the controller path break the normalization function #22
Closed
Description
What happened
When creating a controller with a leading slash the normalization function can't correctly normalize the routing path resulting in the impossiiblity to find the RouteSpec
blocking the application.
Code
class AppController extends Controller {
AppController({super.path = '/api/v1/periodic-table/'}){
on(BenchRoute(path: '/element'), _handleElement);
on(BenchRoute(path: '/shells'), _handleShells);
}
Future<Response> _handleElement(RequestContext context) async {
if(!context.queryParameters.containsKey('symbol')){
throw BadRequestException(message: 'Symbol is required');
}
final String symbol = context.queryParameters['symbol'];
final Map<String, dynamic> element = await context.use<AppProvider>().getElement(symbol);
return Response.json(element);
}
Future<Response> _handleShells(RequestContext context) async {
if(!context.queryParameters.containsKey('symbol')){
throw BadRequestException(message: 'Symbol is required');
}
final String symbol = context.queryParameters['symbol'];
final Map<String, dynamic> shells = await context.use<AppProvider>().getShells(symbol);
return Response.json(shells);
}
}
What should have happened
The normalization function should take care of this edge-case making the router work with no errors.
Metadata
Assignees
Labels
Projects
Status
Closed