Skip to content

Commit 7be6c0c

Browse files
authored
fix: unexpected file request with custom publicDir, fix #4629 (#4631)
1 parent cb90de0 commit 7be6c0c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/vite/src/node/server/middlewares/transform.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ export function transformMiddleware(
114114
}
115115
}
116116

117-
// warn explicit /public/ paths
118-
if (url.startsWith('/public/')) {
117+
const publicPath =
118+
normalizePath(server.config.publicDir).slice(
119+
server.config.root.length
120+
) + '/'
121+
// warn explicit public paths
122+
if (url.startsWith(publicPath)) {
119123
logger.warn(
120124
chalk.yellow(
121125
`files in the public directory are served at the root path.\n` +
122126
`Instead of ${chalk.cyan(url)}, use ${chalk.cyan(
123-
url.replace(/^\/public\//, '/')
127+
url.replace(publicPath, '/')
124128
)}.`
125129
)
126130
)

0 commit comments

Comments
 (0)