Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(nuxt): generate spa fallback for nuxt generate (#7507)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 14, 2022
1 parent b8cb206 commit 9ee5ca2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"knitwork": "^0.1.2",
"magic-string": "^0.26.3",
"mlly": "^0.5.14",
"nitropack": "^0.5.2",
"nitropack": "^0.5.3",
"nuxi": "3.0.0-rc.9",
"ohash": "^0.1.5",
"ohmyfetch": "^0.4.18",
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/core/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export async function initNitro (nuxt: Nuxt) {
prerender: {
crawlLinks: nuxt.options._generate ? nuxt.options.generate.crawler : false,
routes: ([] as string[])
.concat(nuxt.options._generate ? ['/', ...nuxt.options.generate.routes] : [])
.concat(nuxt.options.ssr === false ? ['/', '/200.html', '/404.html'] : [])
.concat(nuxt.options._generate ? ['/', '/200.html', ...nuxt.options.generate.routes] : [])
.concat(nuxt.options.ssr === false ? ['/index.html', '/200.html', '/404.html'] : [])
},
sourceMap: nuxt.options.sourcemap.server,
externals: {
Expand Down
4 changes: 3 additions & 1 deletion packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ const getSPARenderer = lazyCachedFunction(async () => {
const PAYLOAD_CACHE = process.env.prerender ? new Map() : null // TODO: Use LRU cache
const PAYLOAD_URL_RE = /\/_payload(\.[a-zA-Z0-9]+)?.js(\?.*)?$/

const NO_SSR_ROUTES = new Set(['/index.html', '/200.html', '/404.html'])

export default defineRenderHandler(async (event) => {
// Whether we're rendering an error page
const ssrError = event.req.url?.startsWith('/__nuxt_error')
Expand All @@ -130,7 +132,7 @@ export default defineRenderHandler(async (event) => {
req: event.req,
res: event.res,
runtimeConfig: useRuntimeConfig() as NuxtSSRContext['runtimeConfig'],
noSSR: !!event.req.headers['x-nuxt-no-ssr'],
noSSR: !!(event.req.headers['x-nuxt-no-ssr']) || (process.env.prerender ? NO_SSR_ROUTES.has(url) : false),
error: !!ssrError,
nuxt: undefined!, /* NuxtApp */
payload: (ssrError ? { error: ssrError } : {}) as NuxtSSRContext['payload']
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10227,9 +10227,9 @@ __metadata:
languageName: node
linkType: hard

"nitropack@npm:^0.5.2":
version: 0.5.2
resolution: "nitropack@npm:0.5.2"
"nitropack@npm:^0.5.3":
version: 0.5.3
resolution: "nitropack@npm:0.5.3"
dependencies:
"@cloudflare/kv-asset-handler": ^0.2.0
"@netlify/functions": ^1.2.0
Expand All @@ -10243,7 +10243,7 @@ __metadata:
"@rollup/pluginutils": ^4.2.1
"@vercel/nft": ^0.22.1
archiver: ^5.3.1
c12: ^0.2.11
c12: ^0.2.12
chalk: ^5.0.1
chokidar: ^3.5.3
consola: ^2.15.3
Expand Down Expand Up @@ -10292,7 +10292,7 @@ __metadata:
bin:
nitro: dist/cli.mjs
nitropack: dist/cli.mjs
checksum: a27577af6902cbf606c56adcff0c2e88007c0eccfb31b674562fa36f88b91ddf02a2d490b08678aa6912e80ff8fc01502ff19cab4ba9cb488edf2223c89eee2f
checksum: f43ce535feb213b2a7f8c06e44befdb4058e4c6e5f87c5923e35256ab5fee03c9e71d3d7a3b4aa6bc707b371a203f962447ca5a0b1c10b69d0e5466e7cf6e5ee
languageName: node
linkType: hard

Expand Down Expand Up @@ -10752,7 +10752,7 @@ __metadata:
knitwork: ^0.1.2
magic-string: ^0.26.3
mlly: ^0.5.14
nitropack: ^0.5.2
nitropack: ^0.5.3
nuxi: 3.0.0-rc.9
ohash: ^0.1.5
ohmyfetch: ^0.4.18
Expand Down

0 comments on commit 9ee5ca2

Please sign in to comment.