Skip to content

Commit

Permalink
Fix serve broken for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed May 16, 2024
1 parent ff5039f commit 33603df
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 33603df

Please sign in to comment.