mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): disable x-nuxt-no-ssr
header by default (#20024)
This commit is contained in:
parent
61699f864e
commit
c660b39447
@ -189,6 +189,15 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add backward-compatible middleware to respect `x-nuxt-no-ssr` header
|
||||||
|
if (nuxt.options.experimental.respectNoSSRHeader) {
|
||||||
|
nitroConfig.handlers = nitroConfig.handlers || []
|
||||||
|
nitroConfig.handlers.push({
|
||||||
|
handler: resolve(distDir, 'core/runtime/nitro/no-ssr'),
|
||||||
|
middleware: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Register nuxt protection patterns
|
// Register nuxt protection patterns
|
||||||
nitroConfig.rollupConfig!.plugins = await nitroConfig.rollupConfig!.plugins || []
|
nitroConfig.rollupConfig!.plugins = await nitroConfig.rollupConfig!.plugins || []
|
||||||
nitroConfig.rollupConfig!.plugins = Array.isArray(nitroConfig.rollupConfig!.plugins) ? nitroConfig.rollupConfig!.plugins : [nitroConfig.rollupConfig!.plugins]
|
nitroConfig.rollupConfig!.plugins = Array.isArray(nitroConfig.rollupConfig!.plugins) ? nitroConfig.rollupConfig!.plugins : [nitroConfig.rollupConfig!.plugins]
|
||||||
|
8
packages/nuxt/src/core/runtime/nitro/no-ssr.ts
Normal file
8
packages/nuxt/src/core/runtime/nitro/no-ssr.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { defineEventHandler, getRequestHeader } from 'h3'
|
||||||
|
|
||||||
|
export default defineEventHandler((event) => {
|
||||||
|
if (getRequestHeader(event, 'x-nuxt-no-ssr')) {
|
||||||
|
event.context.nuxt = event.context.nuxt || {}
|
||||||
|
event.context.nuxt.noSSR = true
|
||||||
|
}
|
||||||
|
})
|
@ -213,7 +213,7 @@ export default defineRenderHandler(async (event) => {
|
|||||||
runtimeConfig: useRuntimeConfig() as NuxtSSRContext['runtimeConfig'],
|
runtimeConfig: useRuntimeConfig() as NuxtSSRContext['runtimeConfig'],
|
||||||
noSSR:
|
noSSR:
|
||||||
!!(process.env.NUXT_NO_SSR) ||
|
!!(process.env.NUXT_NO_SSR) ||
|
||||||
!!(event.node.req.headers['x-nuxt-no-ssr']) ||
|
event.context.nuxt?.noSSR ||
|
||||||
routeOptions.ssr === false ||
|
routeOptions.ssr === false ||
|
||||||
(process.env.prerender ? PRERENDER_NO_SSR_ROUTES.has(url) : false),
|
(process.env.prerender ? PRERENDER_NO_SSR_ROUTES.has(url) : false),
|
||||||
error: !!ssrError,
|
error: !!ssrError,
|
||||||
|
@ -158,6 +158,9 @@ export default defineUntypedSchema({
|
|||||||
*
|
*
|
||||||
* This can be disabled for most Nuxt sites to reduce the client-side bundle by ~0.5kb.
|
* This can be disabled for most Nuxt sites to reduce the client-side bundle by ~0.5kb.
|
||||||
*/
|
*/
|
||||||
polyfillVueUseHead: true
|
polyfillVueUseHead: true,
|
||||||
|
|
||||||
|
/** Allow disabling Nuxt SSR responses by setting the `x-nuxt-no-ssr` header. */
|
||||||
|
respectNoSSRHeader: false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
1
test/fixtures/basic/nuxt.config.ts
vendored
1
test/fixtures/basic/nuxt.config.ts
vendored
@ -184,6 +184,7 @@ export default defineNuxtConfig({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
experimental: {
|
experimental: {
|
||||||
|
respectNoSSRHeader: true,
|
||||||
clientFallback: true,
|
clientFallback: true,
|
||||||
restoreState: true,
|
restoreState: true,
|
||||||
inlineSSRStyles: id => !!id && !id.includes('assets.vue'),
|
inlineSSRStyles: id => !!id && !id.includes('assets.vue'),
|
||||||
|
Loading…
Reference in New Issue
Block a user