fix(renderer): deep merge runtimeConfig for server (#8856)

This commit is contained in:
pooya parsa 2021-02-19 17:33:00 +01:00 committed by GitHub
parent 5346963585
commit 1b9a9d6449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -103,7 +103,7 @@ export default async (ssrContext) => {
__webpack_public_path__ = joinURL(ssrContext.nuxt.config.app.cdnURL, ssrContext.nuxt.config.app.assetsPath)
}
// Create the app definition and the instance (created for each request)
const { app, router<%= (store ? ', store' : '') %> } = await createApp(ssrContext, { ...ssrContext.runtimeConfig.public, ...ssrContext.runtimeConfig.private })
const { app, router<%= (store ? ', store' : '') %> } = await createApp(ssrContext, ssrContext.runtimeConfig.private)
const _app = new Vue(app)
// Add ssr route path to nuxt context so we can account for page navigation between ssr and csr
ssrContext.nuxt.routePath = app.context.route.path

View File

@ -4,6 +4,7 @@ import consola from 'consola'
import { template } from 'lodash'
import { TARGETS, isModernRequest, urlJoin, waitFor } from '@nuxt/utils'
import { normalizeURL } from 'ufo'
import defu from 'defu'
import SPARenderer from './renderers/spa'
import SSRRenderer from './renderers/ssr'
@ -296,7 +297,7 @@ export default class VueRenderer {
// Set runtime config on renderContext
renderContext.runtimeConfig = {
private: renderContext.spa ? {} : { ...this.options.privateRuntimeConfig },
private: renderContext.spa ? {} : defu(this.options.privateRuntimeConfig, this.options.publicRuntimeConfig),
public: { ...this.options.publicRuntimeConfig }
}

View File

@ -2,12 +2,19 @@ export default {
publicRuntimeConfig: {
baseURL: process.env.BASE_URL,
isFixture: true,
TOKEN: 'default'
TOKEN: 'default',
nested: {
priv: 0,
pub: 1
}
},
privateRuntimeConfig: {
baseURL: '${PUBLIC_URL}${BASE_URL}',
API_SECRET: '',
FOO: '123/${FOO}'
FOO: '123/${FOO}',
nested: {
priv: 1
}
},
serverMiddleware: [
(req, _, next) => {