mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
feat(nuxt): support app config for server routes (#19489)
This commit is contained in:
parent
22cf86edf0
commit
e84ec61eeb
@ -38,7 +38,8 @@ export default defineAppConfig({
|
||||
When adding `theme` to the `app.config`, Nuxt uses Vite or webpack to bundle the code. We can universally access `theme` both when server-rendering the page and in the browser using [useAppConfig](/docs/api/composables/use-app-config) composable.
|
||||
|
||||
::alert{type=info}
|
||||
Support for accessing `useAppConfig()` in Nitro and `server` directory is [coming soon](https://github.com/nuxt/nuxt/issues/14670).
|
||||
<!-- TODO: Remove banner when releasing Nuxt on stable channel -->
|
||||
Support for accessing `useAppConfig()` in Nitro and `server` directory is [coming soon](https://github.com/nuxt/nuxt/pull/19489) and available on [edge-channel](https://nuxt.com/docs/guide/going-further/edge-channel).
|
||||
::
|
||||
|
||||
```js
|
||||
|
@ -47,6 +47,13 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
as: '__publicAssetsURL',
|
||||
name: 'publicAssetsURL',
|
||||
from: resolve(distDir, 'core/runtime/nitro/paths')
|
||||
},
|
||||
{
|
||||
// TODO: Remove after https://github.com/unjs/nitro/issues/1049
|
||||
as: 'defineAppConfig',
|
||||
name: 'defineAppConfig',
|
||||
from: resolve(distDir, 'core/runtime/nitro/config'),
|
||||
priority: -1
|
||||
}
|
||||
],
|
||||
exclude: [...excludePattern, /[\\/]\.git[\\/]/]
|
||||
@ -79,6 +86,10 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
...nuxt.options.runtimeConfig.nitro
|
||||
}
|
||||
},
|
||||
appConfig: nuxt.options.appConfig,
|
||||
appConfigFiles: nuxt.options._layers.map(
|
||||
layer => resolve(layer.config.srcDir, 'app.config')
|
||||
),
|
||||
typescript: {
|
||||
generateTsConfig: false
|
||||
},
|
||||
|
1
packages/nuxt/src/core/runtime/nitro/config.ts
Normal file
1
packages/nuxt/src/core/runtime/nitro/config.ts
Normal file
@ -0,0 +1 @@
|
||||
export const defineAppConfig = (config: any) => config
|
@ -1035,6 +1035,9 @@ describe('app config', () => {
|
||||
}
|
||||
|
||||
expect(html).toContain(JSON.stringify(expectedAppConfig))
|
||||
|
||||
const serverAppConfig = await $fetch('/api/app-config')
|
||||
expect(serverAppConfig).toMatchObject({ appConfig: expectedAppConfig })
|
||||
})
|
||||
})
|
||||
|
||||
|
6
test/fixtures/basic/server/api/app-config.ts
vendored
Normal file
6
test/fixtures/basic/server/api/app-config.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export default defineEventHandler(() => {
|
||||
const appConfig = useAppConfig()
|
||||
return {
|
||||
appConfig
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user