mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-03 16:59:06 +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,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue