-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Allow configuration of cleanUrls
option for serve
command
#7991
Comments
Maybe we could let you pass a JSON string through a single command line option, which we directly merge into the default options? I don't have good API designs so far. |
If the goal is to make the entire For example: Especially if trying to customise the Alternatives
I'm happy to work on a PR if there is a decision on the preferred approach for the API. |
Yeah, I think a |
To me this CLI command is just a convenience for non-technical users to easily test their Docusaurus site. If you don't like it or need something more advanced you can provide your own server. What prevents you from running Not against adding a |
Agreed, that makes sense. It would be out of scope to add all those options from a third-party lib. I can use Would it make sense to change the default from Alternatively, could the script check for an environmental variable Happy that this issue can be closed if deemed out of scope.👍 |
As far as I know, Netlify has pretty URLs by default, although it tells you it doesn't (asset optimization disabled by default, but still pretty URLs enabled) I've documented this here:
This is confusing but it's what I see in practice. Also Netlify pretty URLs is not exactly the same as Vercel cleanUrls. All hosting providers have differences. Netlify pretty URLs will remove a trailing slash but won't redirect if you use HTML file extensions for example. Here's a Netlify deployment with std settings: https://630608910ce7dd006e877866--docusaurus-with-netlify-defaults.netlify.app Also, have you tried deploying a Docusaurus site without pretty URLs? Would our frontend SPA router work with URLs ending with If you want to change this setting, I'd rather ask you to do the homework and show me a Docusaurus site hosted on multiple platforms with cleanUrls: false and trailingSlash true/false combinations.
That's not particularly better to me. If this is a useful option we should expose it properly. But is it a useful option in the first place? I'm still not sure to understand your iframe use-case. What is the easy actionable step-by-step guide for reproducing this problem?
Feel free to close if you don't care much about getting this solved. |
I don't think it's quite out of scope. If some hosting providers have this behavior and others don't, we ought to provide an option to make the local testing env mirror the deployment env. |
I'm ok to add an option for this But if some hosting provider decides to do weird fancy things, I wouldn't make it part of |
Aye, yes, that makes sense |
I've created a stackbiltz example where the site functions correctly on https://stackblitz.com/edit/github-sifwoz?file=docusaurus.config.js It appears that this behaviour only occurs when The example:
|
can I try doing this? |
@SlicedSilver is it possible that it's related to our @rashidmya yes I'm ok to add a |
Within However, if I remove the http 302 'found' redirect logic then it works as well (without changing the // if (!req.url?.startsWith(baseUrl)) {
// res.writeHead(302, {
// Location: baseUrl,
// });
// res.end();
// return;
// } Changing the Location: baseUrl + req.url.slice(1), If changing the location value is the best option then obviously it might make sense to check if baseUrl ends with const slicePoint = (baseUrl.endsWith('/') && req.url.startsWith('/')) ? 1 : 0;
// ...
Location: baseUrl + req.url.slice(slicePoint), @slorber Hope this helps, and thanks for your assistance. |
This tripped us up too. We have some <iframe src={useBaseUrl("/examples/demo.html")}></iframe> This works fine with Reproduction case: https://github.com/MattiasBuelens/docusaurus-serve-html-asset-issue
That seems like a reasonable workaround for us. I'd prefer if |
Have you read the Contributing Guidelines on issues?
Description
Allow configuration of the
cleanUrls
option passed toserve-handler
package when runningdocusaurus serve
.Currently, Docusaurus sets the
cleanUrls
option for theserve-hander
package totrue
and it isn't configurable by the user.docusaurus/packages/docusaurus/src/commands/serve.ts
Lines 76 to 82 in bd9f29a
Proposing that this should be a user-configurable option.
Has this been requested on Canny?
No response
Motivation
By default, at least a few major hosting providers (GH Pages, Netlify, Vercel) don't enable this 'feature'. Having this as an option would allow for more accurate testing of the documentation website before deploying.
A Use Case:
It is possible to embed an iframe into a documentation page which serves as a self-contained example. The example file can be loaded using the
file-loader
web pack loader.This works correctly when using
docusaurus start
and when deploying the build onto a hosting provider. However, when runningdocusaurus serve
, any url ending with.html
is rewritten without the extension and a 404 error occurs.API design
ServeCLIOptions
could includecleanUrls?: boolean;
which defaults totrue
.docusaurus/packages/docusaurus/src/commands/serve.ts
Lines 20 to 25 in bd9f29a
When the user wishes to disable
cleanUrls
then they would call the serve command as follows:docusaurus serve --no-clean-urls
A similar options could be added to the configuration file (https://github.com/facebook/docusaurus/blob/bd9f29a4698963d3b139f7419877a300640b09ff/packages/docusaurus-types/src/config.d.ts).
Have you tried building it?
I've tried the changes locally and passing
cleanUrls: false
toserve-handler
works as expected.Self-service
The text was updated successfully, but these errors were encountered: