mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 01:17:16 +00:00
fix(nitro): resolve alias for serverMiddleware
This commit is contained in:
parent
6e1cb62231
commit
c864c5a30c
@ -57,7 +57,7 @@ export default function nuxt2CompatModule () {
|
|||||||
|
|
||||||
// Resolve middleware
|
// Resolve middleware
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', () => {
|
||||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt.options.serverMiddleware)
|
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
||||||
if (nuxt.server) {
|
if (nuxt.server) {
|
||||||
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { resolve, join, extname } from 'upath'
|
|||||||
import { joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import globby from 'globby'
|
import globby from 'globby'
|
||||||
import { watch } from 'chokidar'
|
import { watch } from 'chokidar'
|
||||||
import { tryResolvePath } from '@nuxt/kit'
|
import { tryResolvePath, Nuxt } from '@nuxt/kit'
|
||||||
|
|
||||||
export interface ServerMiddleware {
|
export interface ServerMiddleware {
|
||||||
route: string
|
route: string
|
||||||
@ -51,11 +51,11 @@ export function scanMiddleware (serverDir: string, onChange?: (results: ServerMi
|
|||||||
return scan()
|
return scan()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveMiddleware (serverMiddleware: any[]) {
|
export function resolveMiddleware (nuxt: Nuxt) {
|
||||||
const middleware: ServerMiddleware[] = []
|
const middleware: ServerMiddleware[] = []
|
||||||
const legacyMiddleware: ServerMiddleware[] = []
|
const legacyMiddleware: ServerMiddleware[] = []
|
||||||
|
|
||||||
for (let m of serverMiddleware) {
|
for (let m of nuxt.options.serverMiddleware) {
|
||||||
if (typeof m === 'string') { m = { handler: m } }
|
if (typeof m === 'string') { m = { handler: m } }
|
||||||
const route = m.path || m.route || '/'
|
const route = m.path || m.route || '/'
|
||||||
const handle = m.handler || m.handle
|
const handle = m.handler || m.handle
|
||||||
@ -67,7 +67,9 @@ export function resolveMiddleware (serverMiddleware: any[]) {
|
|||||||
middleware.push({
|
middleware.push({
|
||||||
...m,
|
...m,
|
||||||
handle: tryResolvePath(handle, {
|
handle: tryResolvePath(handle, {
|
||||||
extensions: ['.ts', '.js']
|
extensions: ['.ts', '.js'],
|
||||||
|
alias: nuxt.options.alias,
|
||||||
|
base: nuxt.options.srcDir
|
||||||
}),
|
}),
|
||||||
route
|
route
|
||||||
})
|
})
|
||||||
|
@ -22,7 +22,7 @@ export function initNitro (nuxt: Nuxt) {
|
|||||||
|
|
||||||
// Resolve middleware
|
// Resolve middleware
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', () => {
|
||||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt.options.serverMiddleware)
|
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
||||||
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
||||||
nitroContext.middleware.push(...middleware)
|
nitroContext.middleware.push(...middleware)
|
||||||
nitroDevContext.middleware.push(...middleware)
|
nitroDevContext.middleware.push(...middleware)
|
||||||
|
Loading…
Reference in New Issue
Block a user