Skip to content

Commit

Permalink
fix: enforce Base URL instead of showing warning
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Sep 4, 2024
1 parent 591a459 commit 8c7c0f4
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions vike/node/runtime/renderPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ async function renderPageAndPrepare(
}

// Check Base URL
{
const pageContextHttpResponse = checkBaseUrl(pageContextInit, httpRequestId)
if (pageContextHttpResponse) return pageContextHttpResponse
}
assertBaseUrl(pageContextInit)

// Normalize URL
{
Expand Down Expand Up @@ -636,23 +633,17 @@ async function handleAbortError(
return { pageContextAbort }
}

function checkBaseUrl(pageContextInit: { urlOriginal: string }, httpRequestId: number) {
function assertBaseUrl(pageContextInit: { urlOriginal: string }) {
const { baseServer } = getGlobalContext()
const { urlOriginal } = pageContextInit
const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal)
const { hasBaseServer } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer)
if (!hasBaseServer) {
logRuntimeInfo?.(
`${getRequestInfoMessage(urlOriginal)} skipped because URL ${prettyUrl(
urlOriginal
)} doesn't start with Base URL ${prettyUrl(baseServer)} (https://vike.dev/base-url)`,
httpRequestId,
'info'
)
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit)
return pageContextHttpResponseNull
}
return null
assertUsage(
hasBaseServer,
`${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(
`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`
)} which doesn't start with Base URL ${prettyUrl(baseServer)} (https://vike.dev/base-url)`
)
}

function prettyUrl(url: string) {
Expand Down

0 comments on commit 8c7c0f4

Please sign in to comment.