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: Remove trailing slash from route path in KoaDriver #1114

Merged
merged 7 commits into from
Apr 19, 2023

Conversation

Aareksio
Copy link
Contributor

@Aareksio Aareksio commented Apr 19, 2023

Description

Before the update, @koa/router allowed path declared with a trailing slash to be accessible both with or without trailing slash

router.get('/user/', handler)

// GET /user -> 200
// GET /user/ -> 200

After the update, only trailing slash path is accessible. This makes registering nested routes with @Get('/') infeasible, when one does not use trailing slashes for URLs.

@JsonController('/user')
export class UserController {
  @Get('/') // <-- this causes the route to become `/user/`
  getUser() {}
}

Proposed change, restricted in scope to affected KoaDriver only, removes the trailing slash if one appears in the route (aside from /). @koa/router allows such paths to be accessed both with and without trailing slash, as before.

Please note @Get('/') is what official tests are using, and it works just fine with express:
https://github.com/typestack/routing-controllers/blob/develop/test/functional/controller-base-routes.spec.ts#L18-L21

Checklist

  • the pull request title describes what this PR does (not a vague title like Update index.md)
  • the pull request targets the default branch of the repository (develop)
  • the code follows the established code style of the repository
    • npm run prettier:check passes
    • npm run lint:check passes
  • tests are added for the changes I made (if any source code was modified)
  • documentation added or updated
  • I have run the project locally and verified that there are no errors

Fixes

Fixes #1113

@attilaorosz
Copy link
Member

This is a nice catch, thanks for the contribution!

@attilaorosz attilaorosz merged commit ac7416c into typestack:develop Apr 19, 2023
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

fix: Breaking Change in 0.10.0, @koa/router and trailing slash
2 participants