Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"rollup": "^2.66.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.5.4",
"scule": "^0.2.1",
"serve-placeholder": "^1.2.4",
"serve-static": "^1.14.2",
"std-env": "^3.0.1",
Expand Down
18 changes: 11 additions & 7 deletions src/runtime/app/config.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import destr from 'destr'
import defu from 'defu'
import { snakeCase } from 'scule'

// Bundled runtime config (injected by nitro)
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])
// baseURL can be overridden by BASE_URL
const envKey = snakeCase(key).toUpperCase()
_runtimeConfig[type][key] = destr(process.env[envKey] || _runtimeConfig[type][key])
if (_runtimeConfig[type][key] && typeof _runtimeConfig[type][key] === 'object') {
for (const subkey in _runtimeConfig[type][key]) {
// key: { subKey } can be overridden by KEY_SUB_KEY`
const envKeyName = `${envKey}_${snakeCase(subkey).toUpperCase()}`
_runtimeConfig[type][key][subkey] = destr(process.env[envKeyName]) || _runtimeConfig[type][key][subkey]
}
}
}
}

// Load dynamic app configuration
const appConfig = _runtimeConfig.public.app
appConfig.baseURL = process.env.NUXT_APP_BASE_URL || appConfig.baseURL
appConfig.cdnURL = process.env.NUXT_APP_CDN_URL || appConfig.cdnURL
appConfig.buildAssetsDir = process.env.NUXT_APP_BUILD_ASSETS_DIR || appConfig.buildAssetsDir

// Named exports
export const privateConfig = deepFreeze(defu(_runtimeConfig.private, _runtimeConfig.public))
export const publicConfig = deepFreeze(_runtimeConfig.public)
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4533,6 +4533,7 @@ __metadata:
rollup: ^2.66.1
rollup-plugin-terser: ^7.0.2
rollup-plugin-visualizer: ^5.5.4
scule: ^0.2.1
serve-placeholder: ^1.2.4
serve-static: ^1.14.2
std-env: ^3.0.1
Expand Down