0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-24 23:21:57 -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); html = subpathNotUsedTemplate(devRoot, pathname);
} else { } else {
// HACK: redirect without the base path for assets in publicDir // HACK: redirect without the base path for assets in publicDir
const redirectTo = if (config.base && !pathname.startsWith(config.base)) {
req.method === 'GET' &&
config.base !== '/' &&
pathname.startsWith(config.base) &&
pathname.replace(config.base, '/');
if (redirectTo && redirectTo !== '/') {
const response = new Response(null, { const response = new Response(null, {
status: 302, status: 301,
headers: { headers: {
Location: redirectTo, Location: pathname.replace(config.base, ''),
}, },
}); });
await writeWebResponse(res, response); await writeWebResponse(res, response);
return; return;
} }
html = notFoundTemplate({ html = notFoundTemplate({
statusCode: 404, statusCode: 404,
title: 'Not found', title: 'Not found',