feat(nitro): support adding node_modules as middleware (#2826)

This commit is contained in:
Daniel Roe 2022-01-21 11:39:22 +00:00 committed by GitHub
parent d0d8e8311c
commit 3b72b318e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
})
}