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 // Expose runtime config
if (process.server) { if (process.server) {
nuxtApp.provide('config', options.ssrContext.runtimeConfig.private) nuxtApp.provide('config', options.ssrContext.runtimeConfig)
nuxtApp.payload.config = options.ssrContext.runtimeConfig.public // Client's runtime-config
nuxtApp.payload.config = {
public: options.ssrContext.runtimeConfig.public,
app: options.ssrContext.runtimeConfig.app
}
} else { } else {
nuxtApp.provide('config', reactive(nuxtApp.payload.config)) nuxtApp.provide('config', reactive(nuxtApp.payload.config))
} }

View File

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