Skip to content
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

fix: import statements should not affect the route matching order #1307

Open
tillkolter opened this issue Dec 14, 2023 · 0 comments
Open

fix: import statements should not affect the route matching order #1307

tillkolter opened this issue Dec 14, 2023 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@tillkolter
Copy link

Description

We found in our project that a different order of Controller imports produces different results for a catch-all 404 route which blocks controllers imported earlier in the file.

A canonical sorting of imports is in my opinion common practice and it is not intuitive that the order matters in this case. Shouldn't the matching preference depend only on factors such as longest path and order inside the initializers controllers array?

Minimal code-snippet showcasing the problem

controllers/NotFoundController.ts

import { Controller, NotFoundError, All } from "routing-controllers";

@Controller()
export class NotFoundController {
  @All("/*")
  catchAll() {
    throw new NotFoundError("This route does not exist");
  }
}

controllers/ApplesController.ts

@JsonController("/apples")
export class ApplesController {
  @Get("/")
  async Apples(
     return JSON.stringify(["Granny Smith", "Braeburn"])
  )
}

app.ts

import { NotFoundController } from "./controllers/NotFoundController";
import { ApplesController } from "./controllers/ApplesController";

export const app = createExpressServer({
  controllers: [
    ApplesController,
    NotFoundController,
  ]
});

Expected behavior

GET http://localhost:3000/apples

["Granny Smith", "Braeburn"]

Actual behavior

GET http://localhost:3000/apples

404 error

@tillkolter tillkolter added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant