Skip to content

Conversation

@mrkstwrt
Copy link
Contributor

Since 2.0 it is not possible to target only /v1/test with the multiple levels of nested prefixes.

The code in this sandbox would add only a single route /v1/test in v1. However in v2 it creates two routes /v1/test and /v1/test/.

This PR adds the option prefixRootOnly which behaves in the old way, adding only a single route.

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@cemremengu cemremengu left a 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`)
Copy link
Member

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)

Copy link
Contributor Author

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 😄

Copy link
Member

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

Copy link
Member

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 /path  and /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.

Copy link
Contributor Author

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?

Copy link
Member

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 ..

@delvedor delvedor added the semver-minor Issue or PR that should land as semver minor label Mar 1, 2019
@mrkstwrt
Copy link
Contributor Author

mrkstwrt commented Mar 7, 2019

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 (prefixTrailingSlash: undefined) matches both, prefixTrailingSlash: true only matches /prefix/ and prefixTrailingSlash: false matches only /prefix.

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`)
Copy link
Member

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 ..

@delvedor delvedor added the v2.x Issue or pr related to Fastify v2 label Mar 9, 2019
@mrkstwrt mrkstwrt force-pushed the prefix-trailing-slash branch from 2bfc99a to 4b2844b Compare March 11, 2019 23:57
Copy link
Member

@Eomm Eomm left a 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?

@mrkstwrt
Copy link
Contributor Author

@Eomm When ignoreTrailingSlash: true it will always match /prefix and /prefix/ with a / route anyway, doesn't matter what is set by prefixTrailingSlash because the slash is ignored at the find-my-way router level

@Eomm
Copy link
Member

Eomm commented Mar 16, 2019

@mrkstwrt Thank you for the clarification 😃

@mcollina Would you like to recheck?
I think your review comments have been addressed 👍

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@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 Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

semver-minor Issue or PR that should land as semver minor v2.x Issue or pr related to Fastify v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants