mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
refactor(nuxt): rename nuxtMiddleware
to appMiddleware
This commit is contained in:
parent
c6aa617839
commit
cac7454702
@ -249,12 +249,12 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({
|
||||
if (isAppManifestEnabled) {
|
||||
const routeRules = await nuxtApp.runWithContext(() => getRouteRules(to.path))
|
||||
|
||||
if (routeRules.nuxtMiddleware) {
|
||||
for (const key in routeRules.nuxtMiddleware) {
|
||||
if (routeRules.appMiddleware) {
|
||||
for (const key in routeRules.appMiddleware) {
|
||||
const guard = nuxtApp._middleware.named[key] as RouteGuard | undefined
|
||||
if (!guard) { return }
|
||||
|
||||
if (routeRules.nuxtMiddleware[key]) {
|
||||
if (routeRules.appMiddleware[key]) {
|
||||
middlewareEntries.add(guard)
|
||||
} else {
|
||||
middlewareEntries.delete(guard)
|
||||
|
@ -267,16 +267,16 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
nuxt.hook('nitro:config', (config) => {
|
||||
const rules = config.routeRules
|
||||
for (const rule in rules) {
|
||||
if (!(rules[rule] as any).nuxtMiddleware) { continue }
|
||||
const value = (rules[rule] as any).nuxtMiddleware
|
||||
if (!(rules[rule] as any).appMiddleware) { continue }
|
||||
const value = (rules[rule] as any).appMiddleware
|
||||
if (typeof value === 'string') {
|
||||
(rules[rule] as NitroOptions['routeRules']).nuxtMiddleware = { [value]: true }
|
||||
(rules[rule] as NitroOptions['routeRules']).appMiddleware = { [value]: true }
|
||||
} else if (Array.isArray(value)) {
|
||||
const normalizedRules: Record<string, boolean> = {}
|
||||
for (const middleware of value) {
|
||||
normalizedRules[middleware] = true
|
||||
}
|
||||
(rules[rule] as NitroOptions['routeRules']).nuxtMiddleware = normalizedRules
|
||||
(rules[rule] as NitroOptions['routeRules']).appMiddleware = normalizedRules
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -291,7 +291,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
||||
const filteredRules = {} as Record<string, any>
|
||||
for (const routeKey in _routeRules[key]) {
|
||||
const value = (_routeRules as any)[key][routeKey]
|
||||
if (['prerender', 'redirect', 'nuxtMiddleware'].includes(routeKey) && value) {
|
||||
if (['prerender', 'redirect', 'appMiddleware'].includes(routeKey) && value) {
|
||||
if (routeKey === 'redirect') {
|
||||
filteredRules[routeKey] = typeof value === 'string' ? value : value.to
|
||||
} else {
|
||||
|
@ -244,7 +244,7 @@ declare module 'nitropack' {
|
||||
interface NitroRouteRules {
|
||||
ssr?: boolean
|
||||
experimentalNoScripts?: boolean
|
||||
nuxtMiddleware?: Record<string, boolean>
|
||||
appMiddleware?: Record<string, boolean>
|
||||
}
|
||||
interface NitroRuntimeHooks {
|
||||
'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise<void>
|
||||
|
@ -477,7 +477,7 @@ export default defineNuxtModule({
|
||||
'}',
|
||||
'declare module \'nitropack\' {',
|
||||
' interface NitroRouteConfig {',
|
||||
' nuxtMiddleware?: MiddlewareKey | MiddlewareKey[] | Record<MiddlewareKey, boolean>',
|
||||
' appMiddleware?: MiddlewareKey | MiddlewareKey[] | Record<MiddlewareKey, boolean>',
|
||||
' }',
|
||||
'}'
|
||||
].join('\n')
|
||||
|
@ -179,9 +179,9 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
|
||||
if (isAppManifestEnabled) {
|
||||
const routeRules = await nuxtApp.runWithContext(() => getRouteRules(to.path))
|
||||
|
||||
if (routeRules.nuxtMiddleware) {
|
||||
for (const key in routeRules.nuxtMiddleware) {
|
||||
if (routeRules.nuxtMiddleware[key]) {
|
||||
if (routeRules.appMiddleware) {
|
||||
for (const key in routeRules.appMiddleware) {
|
||||
if (routeRules.appMiddleware[key]) {
|
||||
middlewareEntries.add(key)
|
||||
} else {
|
||||
middlewareEntries.delete(key)
|
||||
|
@ -26,7 +26,7 @@ declare module 'nitropack' {
|
||||
interface NitroRouteRules {
|
||||
ssr?: boolean
|
||||
experimentalNoScripts?: boolean
|
||||
nuxtMiddleware?: Record<string, boolean>
|
||||
appMiddleware?: Record<string, boolean>
|
||||
}
|
||||
interface NitroRuntimeHooks {
|
||||
'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise<void>
|
||||
|
2
packages/nuxt/types.d.ts
vendored
2
packages/nuxt/types.d.ts
vendored
@ -26,7 +26,7 @@ declare module 'nitropack' {
|
||||
interface NitroRouteRules {
|
||||
ssr?: boolean
|
||||
experimentalNoScripts?: boolean
|
||||
nuxtMiddleware?: Record<string, boolean>
|
||||
appMiddleware?: Record<string, boolean>
|
||||
}
|
||||
interface NitroRuntimeHooks {
|
||||
'dev:ssr-logs': (ctx: { logs: LogObject[], path: string }) => void | Promise<void>
|
||||
|
2
test/fixtures/basic/nuxt.config.ts
vendored
2
test/fixtures/basic/nuxt.config.ts
vendored
@ -60,7 +60,7 @@ export default defineNuxtConfig({
|
||||
},
|
||||
routeRules: {
|
||||
'/route-rules/spa': { ssr: false },
|
||||
'/route-rules/middleware': { nuxtMiddleware: 'route-rules-middleware' },
|
||||
'/route-rules/middleware': { appMiddleware: 'route-rules-middleware' },
|
||||
'/hydration/spa-redirection/**': { ssr: false },
|
||||
'/no-scripts': { experimentalNoScripts: true }
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user