1- import { defineEventHandler , setResponseHeader } from 'h3'
1+ import { defineEventHandler , setResponseHeader , getRequestURL } from 'h3'
22import { useRuntimeConfig } from '#imports'
33// @ts -expect-error - Virtual import
44import entryPath from '#nuxt-entry-path'
@@ -11,8 +11,17 @@ export default defineEventHandler((event) => {
1111 const buildId = config . app . buildId
1212 const baseURL = config . app . baseURL || '/'
1313 const buildAssetsDir = config . app . buildAssetsDir || '/_nuxt/'
14- const cdnURL = config . app . cdnURL || ''
15- const entryPathValue = entryPath
14+
15+ // Set cdnURL - use config if set, otherwise use the current request's origin.
16+ let cdnURL = config . app . cdnURL
17+ if ( ! cdnURL ) {
18+ const requestURL = getRequestURL ( event )
19+ cdnURL = requestURL . port
20+ ? `${ requestURL . protocol } //${ requestURL . hostname } :${ requestURL . port } `
21+ : `${ requestURL . protocol } //${ requestURL . host } `
22+ }
23+
24+ const entryPathValue = cdnURL + entryPath
1625
1726 // Serialize public config (with componentPreview enabled)
1827 // Only include what's needed for the client
@@ -39,7 +48,7 @@ export default defineEventHandler((event) => {
3948 teleports.id = 'teleports';
4049 document.body.insertBefore(teleports, nuxt.nextSibling);
4150
42- // Add Nuxt data script
51+ // Add Nuxt data script - minimal client-side initialization
4352 const nuxtData = document.createElement('script');
4453 nuxtData.type = 'application/json';
4554 nuxtData.setAttribute('data-nuxt-data', 'nuxt-app');
0 commit comments