fix(nuxt3)!: preserve runtime-config structure for client-side (#4267)

This commit is contained in:
pooya parsa 2022-04-11 21:55:43 +02:00 committed by GitHub
parent 0d5ec20a4b
commit 4d1a6ba6ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -120,8 +120,12 @@ export function createNuxtApp (options: CreateOptions) {
// Expose runtime config
if (process.server) {
nuxtApp.provide('config', options.ssrContext.runtimeConfig.private)
nuxtApp.payload.config = options.ssrContext.runtimeConfig.public
nuxtApp.provide('config', options.ssrContext.runtimeConfig)
// Client's runtime-config
nuxtApp.payload.config = {
public: options.ssrContext.runtimeConfig.public,
app: options.ssrContext.runtimeConfig.app
}
} else {
nuxtApp.provide('config', reactive(nuxtApp.payload.config))
}

View File

@ -32,7 +32,7 @@ const getSPARenderer = cachedResult(async () => {
ssrContext.nuxt = {
serverRendered: false,
config: {
...config.public,
public: config.public,
app: config.app
}
}
@ -84,13 +84,12 @@ export default eventHandler(async (event) => {
}
// Initialize ssr context
const config = useRuntimeConfig()
const ssrContext = {
url,
event,
req: event.req,
res: event.res,
runtimeConfig: { private: config, public: { ...config.public, app: config.app } },
runtimeConfig: useRuntimeConfig(),
noSSR: event.req.headers['x-nuxt-no-ssr'],
error: ssrError,