Skip to content

Commit

Permalink
fix: unexpected file request with custom publicDir, fix #4629 (#4631)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 authored Aug 25, 2021
1 parent cb90de0 commit 7be6c0c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vite/src/node/server/middlewares/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ export function transformMiddleware(
}
}

// warn explicit /public/ paths
if (url.startsWith('/public/')) {
const publicPath =
normalizePath(server.config.publicDir).slice(
server.config.root.length
) + '/'
// warn explicit public paths
if (url.startsWith(publicPath)) {
logger.warn(
chalk.yellow(
`files in the public directory are served at the root path.\n` +
`Instead of ${chalk.cyan(url)}, use ${chalk.cyan(
url.replace(/^\/public\//, '/')
url.replace(publicPath, '/')
)}.`
)
)
Expand Down

0 comments on commit 7be6c0c

Please sign in to comment.