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(v2): respect baseUrl in serving command #4924

Merged
merged 8 commits into from
Jun 9, 2021
Merged

fix(v2): respect baseUrl in serving command #4924

merged 8 commits into from
Jun 9, 2021

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jun 7, 2021

Motivation

Resolves #3291

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Set config field baseUrl with value other than "/" and run yarn serve command.

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label Jun 7, 2021
@lex111 lex111 requested a review from slorber as a code owner June 7, 2021 22:46
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 7, 2021
@netlify
Copy link

netlify bot commented Jun 7, 2021

✔️ [V2]

🔨 Explore the source changes: da26cf5

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60c0d48db89505000798bf76

😎 Browse the preview: https://deploy-preview-4924--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jun 7, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 61
🟢 Accessibility 97
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4924--docusaurus-2.netlify.app/

@netlify
Copy link

netlify bot commented Jun 7, 2021

✔️ [V1]

🔨 Explore the source changes: da26cf5

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-1/deploys/60c0d48de639c6000801b91d

😎 Browse the preview: https://deploy-preview-4924--docusaurus-1.netlify.app

@github-actions
Copy link

github-actions bot commented Jun 7, 2021

Size Change: +85 B (0%)

Total Size: 620 kB

Filename Size Change
website/build/assets/css/styles.********.css 87.8 kB +85 B (0%)
ℹ️ View Unchanged
Filename Size Change
website/build/assets/js/main.********.js 443 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 62.1 kB 0 B
website/build/docs/introduction/index.html 235 B 0 B
website/build/index.html 27 kB 0 B

compressed-size-action

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks @lex111 , looks like the solution to modify req.url that Anshul suggested works fine.

Was able to get it working with serve so was wondering why you added an extra lib?

Kept your modifications for now but suggesting a slightly different implementation and only using serve, what do you think?

@@ -79,6 +79,7 @@
"html-minifier-terser": "^5.1.1",
"html-tags": "^3.1.0",
"html-webpack-plugin": "^5.3.1",
"http-proxy": "^1.18.1",
Copy link
Collaborator

Choose a reason for hiding this comment

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

not too fan of introducing another static asset serve library for a specific case

those 2 libs may behave differently regarding a few things like pretty URLs, trailing slashes etc so I'd rather keep only one

const server = http.createServer((req, res) => {
serveHandler(req, res, {
// Automatically redirect requests to /baseUrl/
if (!req.url?.startsWith(baseUrl)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if user access "/" but there is /baseUrl/, user could be automatically redirected to that /baseUrl/, I find this a convenient way to avoid potential bug reports (even if the log is quite clear...)

*/

// Remove baseUrl before calling serveHandler
req.url = req.url?.replace(baseUrl, '/');
Copy link
Collaborator

Choose a reason for hiding this comment

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

no need for any if here, / could be replaced by / (noop)

@lex111
Copy link
Contributor Author

lex111 commented Jun 9, 2021

I thought this was a working solution, but if you can avoid using a proxy server, then I agree with that.

@slorber
Copy link
Collaborator

slorber commented Jun 9, 2021

great, so I'll just do some cleanup and merge, thanks

@slorber slorber merged commit a5d3d28 into master Jun 9, 2021
@lex111 lex111 mentioned this pull request Jun 16, 2021
@slorber slorber deleted the lex111/iss4921 branch August 17, 2021 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The serve command does not respect baseUrl
3 participants