From 7118919a9d6e184ef7e43fb6fed08df1e1b09f2e Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 4 Sep 2024 15:21:53 +0800 Subject: [PATCH] refactor: update isFileServingAllowed --- .../src/node/server/middlewares/static.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/static.ts b/packages/vite/src/node/server/middlewares/static.ts index 4c7a854b3ab9aa..33e0bd161e977d 100644 --- a/packages/vite/src/node/server/middlewares/static.ts +++ b/packages/vite/src/node/server/middlewares/static.ts @@ -211,11 +211,28 @@ export function serveRawFsMiddleware( /** * Check if the url is allowed to be served, via the `server.fs` config. */ +export function isFileServingAllowed( + config: ResolvedConfig, + url: string, +): boolean +/** + * @deprecated Use the `isFileServingAllowed(config, url)` signature instead. + */ export function isFileServingAllowed( url: string, server: ViteDevServer, +): boolean +export function isFileServingAllowed( + configOrUrl: ResolvedConfig | string, + urlOrServer: string | ViteDevServer, ): boolean { - const { config } = server + const config = ( + typeof urlOrServer === 'string' ? configOrUrl : urlOrServer.config + ) as ResolvedConfig + const url = ( + typeof urlOrServer === 'string' ? urlOrServer : configOrUrl + ) as string + if (!config.server.fs.strict) return true const filePath = fsPathFromUrl(url) return isFileLoadingAllowed(config, filePath)