Skip to content

Commit

Permalink
refactor: update isFileServingAllowed (#18029)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Sep 4, 2024
1 parent bbc5da9 commit 64ef6e4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/vite/src/node/server/middlewares/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64ef6e4

Please sign in to comment.