mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
feat(nitro): allow extending nitro context
This commit is contained in:
parent
75b412bf0f
commit
bef9f82a8d
@ -20,8 +20,9 @@ export default function nuxt2CompatModule () {
|
|||||||
nuxt.options.build.indicator = false
|
nuxt.options.build.indicator = false
|
||||||
|
|
||||||
// Create contexts
|
// Create contexts
|
||||||
const nitroContext = getNitroContext(nuxt.options, nuxt.options.nitro || {})
|
const nitroOptions = (nuxt.options as any).nitro || {}
|
||||||
const nitroDevContext = getNitroContext(nuxt.options, { preset: 'dev' })
|
const nitroContext = getNitroContext(nuxt.options, nitroOptions)
|
||||||
|
const nitroDevContext = getNitroContext(nuxt.options, { ...nitroOptions, preset: 'dev' })
|
||||||
|
|
||||||
// Connect hooks
|
// Connect hooks
|
||||||
nuxt.addHooks(nitroContext.nuxtHooks)
|
nuxt.addHooks(nitroContext.nuxtHooks)
|
||||||
@ -65,8 +66,13 @@ export default function nuxt2CompatModule () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Resolve middleware
|
// Wait for all modules to be ready
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', async () => {
|
||||||
|
// Extend nitro with modules
|
||||||
|
await nuxt.callHook('nitro:context', nitroContext)
|
||||||
|
await nuxt.callHook('nitro:context', nitroDevContext)
|
||||||
|
|
||||||
|
// Resolve middleware
|
||||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
||||||
if (nuxt.server) {
|
if (nuxt.server) {
|
||||||
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
||||||
|
@ -3,8 +3,9 @@ import type { Nuxt } from '@nuxt/kit'
|
|||||||
|
|
||||||
export function initNitro (nuxt: Nuxt) {
|
export function initNitro (nuxt: Nuxt) {
|
||||||
// Create contexts
|
// Create contexts
|
||||||
const nitroContext = getNitroContext(nuxt.options, (nuxt.options as any).nitro || {})
|
const nitroOptions = (nuxt.options as any).nitro || {}
|
||||||
const nitroDevContext = getNitroContext(nuxt.options, { preset: 'dev' })
|
const nitroContext = getNitroContext(nuxt.options, nitroOptions)
|
||||||
|
const nitroDevContext = getNitroContext(nuxt.options, { ...nitroOptions, preset: 'dev' })
|
||||||
|
|
||||||
nuxt.server = createDevServer(nitroDevContext)
|
nuxt.server = createDevServer(nitroDevContext)
|
||||||
|
|
||||||
@ -20,8 +21,13 @@ export function initNitro (nuxt: Nuxt) {
|
|||||||
// Expose process.env.NITRO_PRESET
|
// Expose process.env.NITRO_PRESET
|
||||||
nuxt.options.env.NITRO_PRESET = nitroContext.preset
|
nuxt.options.env.NITRO_PRESET = nitroContext.preset
|
||||||
|
|
||||||
// Resolve middleware
|
// Wait for all modules to be ready
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', async () => {
|
||||||
|
// Extend nitro with modules
|
||||||
|
await nuxt.callHook('nitro:context', nitroContext)
|
||||||
|
await nuxt.callHook('nitro:context', nitroDevContext)
|
||||||
|
|
||||||
|
// Resolve middleware
|
||||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
||||||
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
||||||
nitroContext.middleware.push(...middleware)
|
nitroContext.middleware.push(...middleware)
|
||||||
|
Loading…
Reference in New Issue
Block a user