mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +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
|
||||
nuxt.hook('modules:done', () => {
|
||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt.options.serverMiddleware)
|
||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
||||
if (nuxt.server) {
|
||||
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { resolve, join, extname } from 'upath'
|
||||
import { joinURL } from 'ufo'
|
||||
import globby from 'globby'
|
||||
import { watch } from 'chokidar'
|
||||
import { tryResolvePath } from '@nuxt/kit'
|
||||
import { tryResolvePath, Nuxt } from '@nuxt/kit'
|
||||
|
||||
export interface ServerMiddleware {
|
||||
route: string
|
||||
@ -51,11 +51,11 @@ export function scanMiddleware (serverDir: string, onChange?: (results: ServerMi
|
||||
return scan()
|
||||
}
|
||||
|
||||
export function resolveMiddleware (serverMiddleware: any[]) {
|
||||
export function resolveMiddleware (nuxt: Nuxt) {
|
||||
const middleware: ServerMiddleware[] = []
|
||||
const legacyMiddleware: ServerMiddleware[] = []
|
||||
|
||||
for (let m of serverMiddleware) {
|
||||
for (let m of nuxt.options.serverMiddleware) {
|
||||
if (typeof m === 'string') { m = { handler: m } }
|
||||
const route = m.path || m.route || '/'
|
||||
const handle = m.handler || m.handle
|
||||
@ -67,7 +67,9 @@ export function resolveMiddleware (serverMiddleware: any[]) {
|
||||
middleware.push({
|
||||
...m,
|
||||
handle: tryResolvePath(handle, {
|
||||
extensions: ['.ts', '.js']
|
||||
extensions: ['.ts', '.js'],
|
||||
alias: nuxt.options.alias,
|
||||
base: nuxt.options.srcDir
|
||||
}),
|
||||
route
|
||||
})
|
||||
|
@ -22,7 +22,7 @@ export function initNitro (nuxt: Nuxt) {
|
||||
|
||||
// Resolve middleware
|
||||
nuxt.hook('modules:done', () => {
|
||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt.options.serverMiddleware)
|
||||
const { middleware, legacyMiddleware } = resolveMiddleware(nuxt)
|
||||
nuxt.server.setLegacyMiddleware(legacyMiddleware)
|
||||
nitroContext.middleware.push(...middleware)
|
||||
nitroDevContext.middleware.push(...middleware)
|
||||
|
Loading…
Reference in New Issue
Block a user