-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add option to match only prefix root with paths #1487
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
Conversation
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cemremengu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
docs/Routes.md
Outdated
| * `logLevel`: set log level for this route. See below. | ||
| * `config`: object used to store custom configuration. | ||
| * `version`: a [semver](http://semver.org/) compatible string that defined the version of the endpoint. [Example](https://github.com/fastify/fastify/blob/versioned-routes/docs/Routes.md#version). | ||
| * `prefixRootOnly`: when using a `/` url with a prefix, setting this option to true will register only `/prefix` without trailing slash. (Defaults to `false`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure the option name is clear enough.
How about disablePrefixTrailingSlash? (Not sure about this one either)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to anything, to be honest naming this option was the hardest part of the PR 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree! I also think we should add a code example to explain the behavior of the option.
Which usually is better than thousand of words :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we really would like three options here:
- define both
/pathand/path/(default) - define
/path - define
/path/
The default is picked because http://localhost:3000/ and http://localhost:3000 are going to the same route anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this, perhaps a URL of / should only refer to {prefix}/ and another token for url such as . representing just the prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately http://localhost:3000/. is a valid URL. We cannot use ..
|
What do you guys think of my latest commit? Still not sold on the naming but it's a tough one to name. I've updated the tests but I'll update the docs later. Basically default ( Thoguhts? |
docs/Routes.md
Outdated
| * `logLevel`: set log level for this route. See below. | ||
| * `config`: object used to store custom configuration. | ||
| * `version`: a [semver](http://semver.org/) compatible string that defined the version of the endpoint. [Example](https://github.com/fastify/fastify/blob/versioned-routes/docs/Routes.md#version). | ||
| * `prefixRootOnly`: when using a `/` url with a prefix, setting this option to true will register only `/prefix` without trailing slash. (Defaults to `false`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately http://localhost:3000/. is a valid URL. We cannot use ..
2bfc99a to
4b2844b
Compare
Eomm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one question: in case of prefixTrailingSlash: "no-slash", ignoreTrailingSlash: true will win the ignoreTrailingSlash?
|
@Eomm When |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
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. |
Since 2.0 it is not possible to target only
/v1/testwith the multiple levels of nested prefixes.The code in this sandbox would add only a single route
/v1/testin v1. However in v2 it creates two routes/v1/testand/v1/test/.This PR adds the option
prefixRootOnlywhich behaves in the old way, adding only a single route.Checklist
npm run testandnpm run benchmark