routing-controllers
routing-controllers copied to clipboard
fix: create controllers in specified order
Description
Controllers are created in the order they are registered with metadata, not in the order they are passed into the router controller options.
@Controller()
class ThirdController {
@Get('/*')
getAll() {
return 'Third';
}
}
@Controller()
class SecondController {
@Get('/second/*')
getAll() {
return 'Second';
}
}
@Controller()
class FirstController {
@Get('/second/first/*')
getAll() {
return 'First';
}
}
createExpressServer({
controllers: [FirstController, SecondController, ThirdController],
})
Expected behavior
Requests are handle by the First controller, which is the first in the controller order, but last to be registered.
GET /second/first/any
First
Actual behavior
Requests are handle by the Third controller, which is the last in the controller order, but first to be registered.
GET /second/first/any
Third
@getfatday Have you found any workarounds? Or are you using your fork with a fix?
@vesurbag, the workaround is to ensure your imports are in the correct order. Not ideal for larger projects.