Skip to content

Commit 92abf69

Browse files
committed
chore: set json content-type headers
1 parent 6f719c3 commit 92abf69

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

nuxt.config.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default defineNuxtConfig({
8080
'/api/registry/files/**': { isr: true, cache: { maxAge: 365 * 24 * 60 * 60 } },
8181
'/:pkg/.well-known/skills/**': { isr: 3600 },
8282
'/:scope/:pkg/.well-known/skills/**': { isr: 3600 },
83-
'/__og-image__/**': { isr: getISRConfig(60) },
83+
'/__og-image__/**': getISRConfig(60),
8484
'/_avatar/**': { isr: 3600, proxy: 'https://www.gravatar.com/avatar/**' },
8585
'/opensearch.xml': { isr: true },
8686
'/oauth-client-metadata.json': { prerender: true },
@@ -95,14 +95,14 @@ export default defineNuxtConfig({
9595
},
9696
},
9797
// pages
98-
'/package/:name': { isr: getISRConfig(60, { fallback: 'html' }) },
99-
'/package/:name/_payload.json': { isr: getISRConfig(60, { fallback: 'json' }) },
100-
'/package/:name/v/:version': { isr: getISRConfig(60, { fallback: 'html' }) },
101-
'/package/:name/v/:version/_payload.json': { isr: getISRConfig(60, { fallback: 'json' }) },
102-
'/package/:org/:name': { isr: getISRConfig(60, { fallback: 'html' }) },
103-
'/package/:org/:name/_payload.json': { isr: getISRConfig(60, { fallback: 'json' }) },
104-
'/package/:org/:name/v/:version': { isr: getISRConfig(60, { fallback: 'html' }) },
105-
'/package/:org/:name/v/:version/_payload.json': { isr: getISRConfig(60, { fallback: 'json' }) },
98+
'/package/:name': getISRConfig(60, { fallback: 'html' }),
99+
'/package/:name/_payload.json': getISRConfig(60, { fallback: 'json' }),
100+
'/package/:name/v/:version': getISRConfig(60, { fallback: 'html' }),
101+
'/package/:name/v/:version/_payload.json': getISRConfig(60, { fallback: 'json' }),
102+
'/package/:org/:name': getISRConfig(60, { fallback: 'html' }),
103+
'/package/:org/:name/_payload.json': getISRConfig(60, { fallback: 'json' }),
104+
'/package/:org/:name/v/:version': getISRConfig(60, { fallback: 'html' }),
105+
'/package/:org/:name/v/:version/_payload.json': getISRConfig(60, { fallback: 'json' }),
106106
// infinite cache (versioned - doesn't change)
107107
'/package-code/**': { isr: true, cache: { maxAge: 365 * 24 * 60 * 60 } },
108108
'/package-docs/**': { isr: true, cache: { maxAge: 365 * 24 * 60 * 60 } },
@@ -291,12 +291,23 @@ interface ISRConfigOptions {
291291
function getISRConfig(expirationSeconds: number, options: ISRConfigOptions = {}) {
292292
if (options.fallback) {
293293
return {
294-
expiration: expirationSeconds,
295-
fallback:
296-
options.fallback === 'html' ? 'spa.prerender-fallback.html' : 'payload-fallback.json',
297-
} as { expiration: number }
294+
...(options.fallback === 'json'
295+
? {
296+
headers: {
297+
'content-type': 'application/json',
298+
},
299+
}
300+
: {}),
301+
isr: {
302+
expiration: expirationSeconds,
303+
fallback:
304+
options.fallback === 'html' ? 'spa.prerender-fallback.html' : 'payload-fallback.json',
305+
} as { expiration: number },
306+
}
298307
}
299308
return {
300-
expiration: expirationSeconds,
309+
isr: {
310+
expiration: expirationSeconds,
311+
},
301312
}
302313
}

0 commit comments

Comments
 (0)