diff --git a/packages/nitro/src/runtime/app/render.ts b/packages/nitro/src/runtime/app/render.ts index 2e9f00745e..3983cfcfbc 100644 --- a/packages/nitro/src/runtime/app/render.ts +++ b/packages/nitro/src/runtime/app/render.ts @@ -55,7 +55,7 @@ export async function renderMiddleware (req, res: ServerResponse) { let isPayloadReq = false if (url.startsWith(STATIC_ASSETS_BASE) && url.endsWith(PAYLOAD_JS)) { isPayloadReq = true - url = url.substr(STATIC_ASSETS_BASE.length, url.length - STATIC_ASSETS_BASE.length - PAYLOAD_JS.length) + url = url.substr(STATIC_ASSETS_BASE.length, url.length - STATIC_ASSETS_BASE.length - PAYLOAD_JS.length) || '/' } // Initialize ssr context diff --git a/packages/nitro/src/runtime/server/static.ts b/packages/nitro/src/runtime/server/static.ts index 138164015c..b1b2a3e19f 100644 --- a/packages/nitro/src/runtime/server/static.ts +++ b/packages/nitro/src/runtime/server/static.ts @@ -6,6 +6,7 @@ import { getAsset, readAsset } from '#static' const METHODS = ['HEAD', 'GET'] const PUBLIC_PATH = process.env.PUBLIC_PATH // Default: /_nuxt/ const TWO_DAYS = 2 * 60 * 60 * 24 +const STATIC_ASSETS_BASE = process.env.NUXT_STATIC_BASE + '/' + process.env.NUXT_STATIC_VERSION // eslint-disable-next-line export default async function serveStatic(req, res) { @@ -27,7 +28,7 @@ export default async function serveStatic(req, res) { } if (!asset) { - if (id.startsWith(PUBLIC_PATH)) { + if (id.startsWith(PUBLIC_PATH) && !id.startsWith(STATIC_ASSETS_BASE)) { throw createError({ statusMessage: 'Cannot find static asset ' + id, statusCode: 404