Skip to content

Commit

Permalink
fix: improve Vite request URL check
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Sep 4, 2024
1 parent 3f4f218 commit 9bb3c2d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions vike/node/runtime/renderPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ async function renderPage<
assert(hasProp(pageContextInit, 'urlOriginal', 'string')) // assertUsage() already implemented at assertArguments()
assertEnv()
assertIsUrl(pageContextInit.urlOriginal)
assertIsNotViteRequest(pageContextInit.urlOriginal)
const urlPathnameWithBase = parseUrl(pageContextInit.urlOriginal, '/').pathname
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal)

if (isIgnoredUrl(pageContextInit.urlOriginal)) {
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit)
Expand Down Expand Up @@ -485,9 +486,9 @@ function assertIsUrl(urlOriginal: string) {
)} which isn't a valid URL.`
)
}
function assertIsNotViteRequest(urlOriginal: string) {
function assertIsNotViteRequest(urlPathname: string, urlOriginal: string) {
const isViteRequest =
urlOriginal.endsWith('/@vite/client') || urlOriginal.startsWith('/@fs/') || urlOriginal.endsWith('/__vite_ping')
urlPathname.startsWith('/@vite/client') || urlPathname.startsWith('/@fs/') || urlPathname.startsWith('/__vite_ping')
assertUsage(
!isViteRequest,
`${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(
Expand Down

0 comments on commit 9bb3c2d

Please sign in to comment.