Skip to content

Commit 87f0023

Browse files
authored
fix(core): fix docusaurus serve broken for assets when using trailingSlash (#10142)
1 parent ff5039f commit 87f0023

File tree

1 file changed

+15
-4
lines changed
  • packages/docusaurus/src/commands

1 file changed

+15
-4
lines changed

packages/docusaurus/src/commands/serve.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,21 @@ export async function serve(
7676

7777
// We do the redirect ourselves for a good reason
7878
// server-handler is annoying and won't include /baseUrl/ in redirects
79-
const normalizedUrl = applyTrailingSlash(req.url, {trailingSlash, baseUrl});
80-
if (req.url !== normalizedUrl) {
81-
redirect(res, normalizedUrl);
82-
return;
79+
// See https://github.com/facebook/docusaurus/issues/10078#issuecomment-2084932934
80+
if (baseUrl !== '/') {
81+
// Not super robust, but should be good enough for our use case
82+
// See https://github.com/facebook/docusaurus/pull/10090
83+
const looksLikeAsset = !!req.url.match(/.[a-z]{1,4}$/);
84+
if (!looksLikeAsset) {
85+
const normalizedUrl = applyTrailingSlash(req.url, {
86+
trailingSlash,
87+
baseUrl,
88+
});
89+
if (req.url !== normalizedUrl) {
90+
redirect(res, normalizedUrl);
91+
return;
92+
}
93+
}
8394
}
8495

8596
// Remove baseUrl before calling serveHandler, because /baseUrl/ should

0 commit comments

Comments
 (0)