From acf3205b31db164dc2dccf7fcecefeddd9a00ecb Mon Sep 17 00:00:00 2001 From: yoho Date: Tue, 8 Mar 2022 21:11:02 +0800 Subject: [PATCH] fix: root import --- packages/vite/src/node/server/middlewares/base.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/base.ts b/packages/vite/src/node/server/middlewares/base.ts index b72f0fd7949f0b..adcaf3c8d6d250 100644 --- a/packages/vite/src/node/server/middlewares/base.ts +++ b/packages/vite/src/node/server/middlewares/base.ts @@ -7,7 +7,7 @@ import type { Connect } from 'types/connect' export function baseMiddleware({ config }: ViteDevServer): Connect.NextHandleFunction { - const base = config.base + const { base, root } = config // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...` return function viteBaseMiddleware(req, res, next) { @@ -15,6 +15,12 @@ export function baseMiddleware({ const parsed = parseUrl(url) const path = parsed.pathname || '/' + if (path.startsWith(root)) { + // If set the base URL to root on Linux, need to replace root to emtry string (#7220) + req.url = url.replace(root, '') + return next() + } + if (path.startsWith(base)) { // rewrite url to remove base.. this ensures that other middleware does // not need to consider base being prepended or not