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(core): fix docusaurus serve broken for assets when using trailingSlash #10142

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/docusaurus/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,21 @@ export async function serve(

// We do the redirect ourselves for a good reason
// server-handler is annoying and won't include /baseUrl/ in redirects
const normalizedUrl = applyTrailingSlash(req.url, {trailingSlash, baseUrl});
if (req.url !== normalizedUrl) {
redirect(res, normalizedUrl);
return;
// See https://github.com/facebook/docusaurus/issues/10078#issuecomment-2084932934
if (baseUrl !== '/') {
// Not super robust, but should be good enough for our use case
// See https://github.com/facebook/docusaurus/pull/10090
const looksLikeAsset = !!req.url.match(/.[a-z]{1,4}$/);

Choose a reason for hiding this comment

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

Maybe *.mp3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, not sure why I assumed extensions could only contain lowercase letters 😅

#10145

if (!looksLikeAsset) {
const normalizedUrl = applyTrailingSlash(req.url, {
trailingSlash,
baseUrl,
});
if (req.url !== normalizedUrl) {
redirect(res, normalizedUrl);
return;
}
}
}

// Remove baseUrl before calling serveHandler, because /baseUrl/ should
Expand Down
Loading