mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
feat(nitro): support adding node_modules
as middleware (#2826)
This commit is contained in:
parent
d0d8e8311c
commit
3b72b318e2
@ -2,7 +2,7 @@ import { resolve, join, extname } from 'pathe'
|
|||||||
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 { tryResolveModule, tryResolvePath } from '@nuxt/kit'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import type { Middleware } from 'h3'
|
import type { Middleware } from 'h3'
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ export function resolveMiddleware (nuxt: Nuxt) {
|
|||||||
const legacyMiddleware: ServerMiddleware[] = []
|
const legacyMiddleware: ServerMiddleware[] = []
|
||||||
|
|
||||||
for (let m of nuxt.options.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 route = m.path || m.route || '/'
|
||||||
const handle = m.handler || m.handle
|
const handle = m.handler || m.handle
|
||||||
if (typeof handle !== 'string' || typeof route !== 'string') {
|
if (typeof handle !== 'string' || typeof route !== 'string') {
|
||||||
@ -87,7 +87,7 @@ export function resolveMiddleware (nuxt: Nuxt) {
|
|||||||
extensions: ['.ts', '.mjs', '.js', '.cjs'],
|
extensions: ['.ts', '.mjs', '.js', '.cjs'],
|
||||||
alias: nuxt.options.alias,
|
alias: nuxt.options.alias,
|
||||||
base: nuxt.options.srcDir
|
base: nuxt.options.srcDir
|
||||||
}),
|
}) || tryResolveModule(handle, { paths: nuxt.options.modulesDir }),
|
||||||
route
|
route
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user