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
3 changes: 3 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ export async function setupAppBridge (_options: any) {
}
})

// Normalize runtimeConfig with a proxy
addPlugin({ src: resolve(distDir, 'runtime/config.plugin.mjs') })

addPlugin({
src: resolve(distDir, 'runtime/error.plugin.server.mjs'),
mode: 'server'
Expand Down
18 changes: 1 addition & 17 deletions src/runtime/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,8 @@ export const useRuntimeConfig = () => {
if (nuxtApp._config) {
return nuxtApp._config as RuntimeConfig
}
const config = reactive(nuxtApp.$config)
nuxtApp._config = new Proxy(config, {
get (target, prop) {
if (prop === 'public') {
return target.public
}
return target[prop] ?? target.public[prop]
},
set (target, prop, value) {
if (prop === 'public' || prop === 'app') {
return false // Throws TypeError
}
target[prop] = value
target.public[prop] = value
return true
}
})

nuxtApp._config = reactive(nuxtApp.$config)
return nuxtApp._config as RuntimeConfig
}

Expand Down
21 changes: 21 additions & 0 deletions src/runtime/config.plugin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default (ctx) => {
const config = ctx.$config
ctx.$config = new Proxy(config, {
get (target, prop) {
if (prop === 'public') {
return target.public
}
return target[prop] ?? target.public?.[prop]
},
set (target, prop, value) {
if (prop === 'public' || prop === 'app') {
return false // Throws TypeError
}
target[prop] = value
if ('public' in target) {
target.public[prop] = value
}
return true
}
})
}