feat(nitro): #config

This commit is contained in:
Pooya Parsa 2021-06-04 22:12:32 +02:00
parent f98be4bfed
commit 0b7790f6d0
3 changed files with 10 additions and 15 deletions

View File

@ -196,6 +196,7 @@ export const getRollupConfig = (nitroContext: NitroContext) => {
entries: {
'#nitro': nitroContext._internal.runtimeDir,
'#nitro-renderer': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app', renderer)),
'#config': require.resolve(resolve(nitroContext._internal.runtimeDir, 'app/config')),
'#nitro-vue-renderer': vue2ServerRenderer,
'#build': nitroContext._nuxt.buildDir,
'~': nitroContext._nuxt.srcDir,

View File

@ -1,19 +1,16 @@
import destr from 'destr'
import defu from 'defu'
const runtimeConfig = process.env.RUNTIME_CONFIG as any
// Bundled runtime config
export const runtimeConfig = process.env.RUNTIME_CONFIG as any
// Allow override from process.env and deserialize
for (const type of ['private', 'public']) {
for (const key in runtimeConfig[type]) {
runtimeConfig[type][key] = destr(process.env[key] || runtimeConfig[type][key])
}
}
const $config = globalThis.$config = {
...runtimeConfig.public,
...runtimeConfig.private
}
export default {
public: runtimeConfig.public,
private: $config
}
// Export merged config
export const config = defu(runtimeConfig.private, runtimeConfig.public)
export default config

View File

@ -1,6 +1,6 @@
import { createRenderer } from 'vue-bundle-renderer'
import devalue from '@nuxt/devalue'
import config from './config'
import { runtimeConfig } from './config'
// @ts-ignore
import htmlTemplate from '#build/views/document.template.js'
@ -41,10 +41,7 @@ export async function renderMiddleware (req, res) {
url,
req,
res,
runtimeConfig: {
public: config.public,
private: config.private
},
runtimeConfig,
...(req.context || {})
}
const renderer = await loadRenderer()