@@ -108,7 +108,7 @@ export default defineNuxtConfig({
108108 '/api/registry/package-meta/**' : { isr : 300 } ,
109109 '/:pkg/.well-known/skills/**' : { isr : 3600 } ,
110110 '/:scope/:pkg/.well-known/skills/**' : { isr : 3600 } ,
111- '/__og-image__/**' : { isr : getISRConfig ( 60 ) } ,
111+ '/__og-image__/**' : getISRConfig ( 60 ) ,
112112 '/_avatar/**' : { isr : 3600 , proxy : 'https://www.gravatar.com/avatar/**' } ,
113113 '/opensearch.xml' : { isr : true } ,
114114 '/oauth-client-metadata.json' : { prerender : true } ,
@@ -123,10 +123,14 @@ export default defineNuxtConfig({
123123 } ,
124124 } ,
125125 // pages
126- '/package/:name' : { isr : getISRConfig ( 60 , true ) } ,
127- '/package/:name/v/:version' : { isr : getISRConfig ( 60 , true ) } ,
128- '/package/:org/:name' : { isr : getISRConfig ( 60 , true ) } ,
129- '/package/:org/:name/v/:version' : { isr : getISRConfig ( 60 , true ) } ,
126+ '/package/:name' : getISRConfig ( 60 , { fallback : 'html' } ) ,
127+ '/package/:name/_payload.json' : getISRConfig ( 60 , { fallback : 'json' } ) ,
128+ '/package/:name/v/:version' : getISRConfig ( 60 , { fallback : 'html' } ) ,
129+ '/package/:name/v/:version/_payload.json' : getISRConfig ( 60 , { fallback : 'json' } ) ,
130+ '/package/:org/:name' : getISRConfig ( 60 , { fallback : 'html' } ) ,
131+ '/package/:org/:name/_payload.json' : getISRConfig ( 60 , { fallback : 'json' } ) ,
132+ '/package/:org/:name/v/:version' : getISRConfig ( 60 , { fallback : 'html' } ) ,
133+ '/package/:org/:name/v/:version/_payload.json' : getISRConfig ( 60 , { fallback : 'json' } ) ,
130134 // infinite cache (versioned - doesn't change)
131135 '/package-code/**' : { isr : true , cache : { maxAge : 365 * 24 * 60 * 60 } } ,
132136 '/package-docs/**' : { isr : true , cache : { maxAge : 365 * 24 * 60 * 60 } } ,
@@ -314,14 +318,23 @@ export default defineNuxtConfig({
314318 } ,
315319} )
316320
317- function getISRConfig ( expirationSeconds : number , fallback = false ) {
318- if ( fallback ) {
321+ interface ISRConfigOptions {
322+ fallback ?: 'html' | 'json'
323+ }
324+ function getISRConfig ( expirationSeconds : number , options : ISRConfigOptions = { } ) {
325+ if ( options . fallback ) {
319326 return {
320- expiration : expirationSeconds ,
321- fallback : 'spa.prerender-fallback.html' ,
322- } as { expiration : number }
327+ isr : {
328+ expiration : expirationSeconds ,
329+ fallback :
330+ options . fallback === 'html' ? 'spa.prerender-fallback.html' : 'payload-fallback.json' ,
331+ initialHeaders : options . fallback === 'json' ? { 'content-type' : 'application/json' } : { } ,
332+ } as { expiration : number } ,
333+ }
323334 }
324335 return {
325- expiration : expirationSeconds ,
336+ isr : {
337+ expiration : expirationSeconds ,
338+ } ,
326339 }
327340}
0 commit comments