0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-17 23:11:29 -05:00

hack: handle base path in dev for /public assets

This commit is contained in:
Tony Sullivan 2022-04-20 16:26:09 +02:00
parent 3e54ee720c
commit a9132217eb

View file

@ -112,23 +112,16 @@ async function handle404Response(
html = subpathNotUsedTemplate(devRoot, pathname);
} else {
// HACK: redirect without the base path for assets in publicDir
const redirectTo =
req.method === 'GET' &&
config.base !== '/' &&
pathname.startsWith(config.base) &&
pathname.replace(config.base, '/');
if (redirectTo && redirectTo !== '/') {
if (config.base && !pathname.startsWith(config.base)) {
const response = new Response(null, {
status: 302,
status: 301,
headers: {
Location: redirectTo,
Location: pathname.replace(config.base, ''),
},
});
await writeWebResponse(res, response);
return;
}
html = notFoundTemplate({
statusCode: 404,
title: 'Not found',