From a9132217eb9ad003f0dca839cb8ef8b5dba5c592 Mon Sep 17 00:00:00 2001 From: Tony Sullivan Date: Wed, 20 Apr 2022 16:26:09 +0200 Subject: [PATCH] hack: handle base path in dev for /public assets --- .../astro/src/vite-plugin-astro-server/index.ts | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts index 0fdb8705b7..2c457eb175 100644 --- a/packages/astro/src/vite-plugin-astro-server/index.ts +++ b/packages/astro/src/vite-plugin-astro-server/index.ts @@ -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',