Skip to content

question: conflicting routes #213

Closed
@codedoge

Description

@codedoge

Hi,
If I build a controller like this:

@JsonController()
export class ItemController {

    @Get("/items/:itemId")
    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"};
    }

}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions