don't serve stale server side props from pwa

This commit is contained in:
keyan 2023-06-01 20:11:29 -05:00
parent d4988694c8
commit d65763ab27
1 changed files with 31 additions and 1 deletions

View File

@ -1,5 +1,6 @@
const { withPlausibleProxy } = require('next-plausible')
const withPWA = require('next-pwa')
const defaultRuntimeCaching = require('next-pwa/cache')
const isProd = process.env.NODE_ENV === 'production'
const corsHeaders = [
@ -13,6 +14,21 @@ const corsHeaders = [
}
]
console.log([
{
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
handler: 'NetworkFirst',
options: {
cacheName: 'next-data',
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60 // 24 hours
}
}
},
...defaultRuntimeCaching.filter((c) => c.options.cacheName !== 'next-data')
])
// XXX this fragile ... eb could change the version label ... but it works for now
const commitHash = isProd
? Object.keys(require('/opt/elasticbeanstalk/deployment/app_version_manifest.json').RuntimeSources['stacker.news'])[0].match(/^app-(.+)-/)[1] // eslint-disable-line
@ -21,7 +37,21 @@ const commitHash = isProd
module.exports = withPWA({
dest: 'public',
register: true,
customWorkerDir: 'sw'
customWorkerDir: 'sw',
runtimeCaching: [
{
urlPattern: /\/_next\/data\/.+\/.+\.json$/i,
handler: 'NetworkFirst',
options: {
cacheName: 'next-data',
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60 // 24 hours
}
}
},
...defaultRuntimeCaching.filter((c) => c.options.cacheName !== 'next-data')
]
})(
withPlausibleProxy()({
env: {