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

serve: with base: '/docs/', should /docs work as /docs/? #8770

Closed
7 tasks done
JounQin opened this issue Jun 24, 2022 · 12 comments · Fixed by #10723
Closed
7 tasks done

serve: with base: '/docs/', should /docs work as /docs/? #8770

JounQin opened this issue Jun 24, 2022 · 12 comments · Fixed by #10723
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@JounQin
Copy link
Contributor

JounQin commented Jun 24, 2022

Describe the bug

When run with vitepress dev docs --base /docs/ and visit /docs route, it will be response with a message:

The server is configured with a public base URL of /docs/ - did you mean to visit [/docs/docs](http://localhost:3000/docs/docs) instead?

I would expect /docs render same as /docs/ or just redirect to /docs/ instead.

Related vuejs/vitepress#852

Reproduction

https://github.com/JounQin/test/tree/vitepress

System Info

System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Max
    Memory: 20.53 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/Library/Caches/fnm_multishells/50102_1656090482477/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/50102_1656090482477/bin/yarn
    npm: 8.13.1 - ~/Library/Caches/fnm_multishells/50102_1656090482477/bin/npm
  Browsers:
    Chrome: 103.0.5060.53
    Firefox: 101.0.1
    Safari: 16.0
  npmPackages:
    @vitejs/plugin-react: ^1.3.2 => 1.3.2 
    vite: ^2.9.12 => 2.9.12

Used Package Manager

yarn

Logs

N/A

Validations

@JounQin JounQin changed the title With base: '/docs'/, should /docs work as /docs/? serve: with base: '/docs'/, should /docs work as /docs/? Jun 24, 2022
@JounQin JounQin changed the title serve: with base: '/docs'/, should /docs work as /docs/? serve: with base: '/docs/', should /docs work as /docs/? Jun 24, 2022
@sapphi-red
Copy link
Member

I think this is expected. /docs is outside of /docs/.

That said, IMHO changing the message to below would be friendly.

did you mean to visit [/docs/docs](http://localhost:3000/docs/docs) or [/docs/](http://localhost:3000/docs/) instead?

@JounQin
Copy link
Contributor Author

JounQin commented Jul 3, 2022

We now consider `` same as /, what means `http://localhost:3000` is exactly same as `http://localhost:3000/`, the consistent behavior should be `http://localhost:3000/docs` vs`http://localhost:3000/docs/`.

@sapphi-red
Copy link
Member

sapphi-red commented Jul 3, 2022

In URL spec, http://localhost:3000 is equivalent to http://localhost:3000/, but http://localhost:3000/docs is not equivalent to http://localhost:3000/docs/.

new URL('http://localhost:3000').href === new URL('http://localhost:3000/').href // true
new URL('http://localhost:3000/docs').href === new URL('http://localhost:3000/docs/').href // false

https://url.spec.whatwg.org/#url-equivalence

Vite is not doing something special here.

@JounQin
Copy link
Contributor Author

JounQin commented Jul 3, 2022

As a user it is very common to visit /docs instead of /docs/ just like `` vs /, and the current behavior is meaningless for end user because there could never be a `/docs` page? It's a UX issue.

@userquin
Copy link
Contributor

userquin commented Jul 3, 2022

It is a server configuration issue, if you want to have this behavior, add a server middleware to do a redirection or forwarding, maybe we can add an option to enable it in the dev server and also in the preview.

I configure my production servers when using some context/scope instead root.

@sapphi-red
Copy link
Member

sapphi-red commented Jul 3, 2022

I understand that but it is confusing if /docs returns the content of /docs/.
I think it is ok to change the message.

Maybe it is not confusing if the redirect works after some seconds like <meta http-equiv="refresh" content="3;url=http://localhost:3000/docs/" />.

@JounQin
Copy link
Contributor Author

JounQin commented Jul 3, 2022

It is a server configuration issue

Right, that's why it should 'fixed' in serve command.

@JounQin
Copy link
Contributor Author

JounQin commented Jul 3, 2022

I understand that but it is confusing if /docs returns the content of /docs/.

My fix is just doing a redirect from /docs to /docs/, it should not be confusing?

Maybe it is not confusing if the redirect works after some seconds like <meta http-equiv="refresh" content="3;url=http://localhost:3000/docs/" />.

It's still meaningless for an end user to understand the difference between /docs/ and /docs? Why should they care about that?

@JounQin
Copy link
Contributor Author

JounQin commented Jul 3, 2022

maybe we can add an option to enable it in the dev server and also in the preview

I believe that option is not very helpful? When would an end user expect /docs results different from /docs/ when there can never be a /docs page?

@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Jul 3, 2022
@sapphi-red
Copy link
Member

It's still meaningless for an end user to understand the difference between /docs/ and /docs? Why should they care about that?

I think it is not completely meaningless but I agree that a user does not need to care about it usually.

@JounQin
Copy link
Contributor Author

JounQin commented Jul 3, 2022

@sapphi-red I've just rebased #8772, please help to review, it should fix serve and preview at the same time.

@jiesir
Copy link

jiesir commented Jul 22, 2022

I also encountered the same problem, after changing 'base', many links still can't be added...

patak-dev pushed a commit that referenced this issue Nov 12, 2022
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Closes #9236
Closes #8770
Closes #8772
tony19 pushed a commit to tony19/vite-docs-template that referenced this issue Nov 12, 2022
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Closes vitejs/vite#9236
Closes vitejs/vite#8770
Closes vitejs/vite#8772
docschina-bot pushed a commit to vitejs/docs-cn that referenced this issue Nov 12, 2022
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Closes vitejs/vite#9236
Closes vitejs/vite#8770
Closes vitejs/vite#8772
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants