mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix(core): fix docusaurus serve
broken for assets when using trailingSlash (#10142)
This commit is contained in:
parent
ff5039f413
commit
87f0023eb3
1 changed files with 15 additions and 4 deletions
|
@ -76,11 +76,22 @@ export async function serve(
|
||||||
|
|
||||||
// We do the redirect ourselves for a good reason
|
// We do the redirect ourselves for a good reason
|
||||||
// server-handler is annoying and won't include /baseUrl/ in redirects
|
// server-handler is annoying and won't include /baseUrl/ in redirects
|
||||||
const normalizedUrl = applyTrailingSlash(req.url, {trailingSlash, baseUrl});
|
// 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) {
|
if (req.url !== normalizedUrl) {
|
||||||
redirect(res, normalizedUrl);
|
redirect(res, normalizedUrl);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove baseUrl before calling serveHandler, because /baseUrl/ should
|
// Remove baseUrl before calling serveHandler, because /baseUrl/ should
|
||||||
// serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
// serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue