-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
question: conflicting routes #213
Comments
Routing controllers will match both routes because your So it would looks like: @JsonController()
export class ItemController {
@Get('items/:itemId([0-9]+)')
getItem(@Param("itemId") itemId: number) {
log.info("/items/:itemId")
return {message: "/items/:itemId"};
}
@Get('/items/all')
getAllItems() {
log.info("/items/all")
return {message: "/items/all"};
}
} |
Thank you for the solution and the formatting tip, it solved my problem. |
Can I suggest that @NoNameProvided's comment be added to the docs, until I saw this it wasn't clear to me how to use a regex in routing params. |
I have mongodb and this regex will not be helpful for me so what should I do |
i use this pattern @JsonController()
export class ItemController {
@Get("/items/:itemId([0-9a-fA-F]{24})")
getItem(@Param("itemId") itemId: number) {
log.info("/items/:itemId")
// if (itemId == "all")return this.getAllItems();
// return new ItemModel({ite_id: itemId}).fetch().then(marshalBookshelf);
return {message: "/items/:itemId"};
}
@Get(new RegExp("/items/all"))
getAllItems() {
log.info("/items/all")
return {message: "/items/all"};
}
} |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi,
If I build a controller like this:
and I try to GET "/items/all", I notice that both methods are invoked.
I know that this is not a good way to implement a REST api, in fact I doscourage this, however I'm shifting from a legacy project and I would like to move to routing-controllers. I noticed that by using the native express way to declare routes (like in the legacy project), the route being selected when invoking "/items/all" is only one ("/items/all"), so there are no multiple route handlers being executed.
The text was updated successfully, but these errors were encountered: