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: create controllers in specified order #774

Open
getfatday opened this issue Sep 16, 2021 · 2 comments · May be fixed by #775
Open

fix: create controllers in specified order #774

getfatday opened this issue Sep 16, 2021 · 2 comments · May be fixed by #775
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@getfatday
Copy link

getfatday commented Sep 16, 2021

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 getfatday added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Sep 16, 2021
getfatday added a commit to getfatday/routing-controllers that referenced this issue Sep 16, 2021
@getfatday getfatday linked a pull request Sep 16, 2021 that will close this issue
6 tasks
getfatday added a commit to getfatday/routing-controllers that referenced this issue Sep 16, 2021
@vesurbag
Copy link

@getfatday Have you found any workarounds? Or are you using your fork with a fix?

@getfatday
Copy link
Author

@vesurbag, the workaround is to ensure your imports are in the correct order. Not ideal for larger projects.

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

Successfully merging a pull request may close this issue.

2 participants