Skip to content

Commit

Permalink
fix(core): fix docusaurus serve broken for assets when using traili…
Browse files Browse the repository at this point in the history
…ngSlash (#10142)
  • Loading branch information
slorber committed May 16, 2024
1 parent ff5039f commit 87f0023
Showing 1 changed file with 15 additions and 4 deletions.
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}$/);
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

0 comments on commit 87f0023

Please sign in to comment.