diff --git a/packages/nitro/src/server/middleware.ts b/packages/nitro/src/server/middleware.ts index 6f4e3a8a79..e90ff78083 100644 --- a/packages/nitro/src/server/middleware.ts +++ b/packages/nitro/src/server/middleware.ts @@ -2,7 +2,7 @@ import { resolve, join, extname } from 'pathe' import { joinURL } from 'ufo' import { globby } from 'globby' import { watch } from 'chokidar' -import { tryResolvePath } from '@nuxt/kit' +import { tryResolveModule, tryResolvePath } from '@nuxt/kit' import type { Nuxt } from '@nuxt/schema' import type { Middleware } from 'h3' @@ -73,7 +73,7 @@ export function resolveMiddleware (nuxt: Nuxt) { const legacyMiddleware: ServerMiddleware[] = [] for (let m of nuxt.options.serverMiddleware) { - if (typeof m === 'string') { m = { handler: m } } + if (typeof m === 'string' || typeof m === 'function' /* legacy middleware */) { m = { handler: m } } const route = m.path || m.route || '/' const handle = m.handler || m.handle if (typeof handle !== 'string' || typeof route !== 'string') { @@ -87,7 +87,7 @@ export function resolveMiddleware (nuxt: Nuxt) { extensions: ['.ts', '.mjs', '.js', '.cjs'], alias: nuxt.options.alias, base: nuxt.options.srcDir - }), + }) || tryResolveModule(handle, { paths: nuxt.options.modulesDir }), route }) }