mirror of
https://github.com/acid-info/logos-press-engine.git
synced 2025-02-23 14:48:08 +00:00
fix: ensure Strapi service clears cache upon webhook calls
This commit is contained in:
parent
c218b89da4
commit
94a4613d72
@ -19,7 +19,10 @@ export const getWebhookData = async (): Promise<WebhookData> =>
|
||||
JSON.parse((await readFile(WEBHOOK_DATA_PATH, 'utf-8')) || '{}')
|
||||
|
||||
let initialized = false
|
||||
if (!IS_VERCEL && !initialized) writeWebhookData({ lastUpdate: +new Date() })
|
||||
if (!IS_VERCEL && !initialized) {
|
||||
writeWebhookData({ lastUpdate: +new Date() })
|
||||
initialized = true
|
||||
}
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
|
@ -72,7 +72,7 @@ export class StrapiService {
|
||||
},
|
||||
})
|
||||
|
||||
if (!isVercel() && process.env.NODE_ENV !== 'development') {
|
||||
if (!isVercel()) {
|
||||
this.checkForUpdate()
|
||||
} else {
|
||||
setInterval(this.clearCache.bind(this), 5000)
|
||||
@ -85,12 +85,15 @@ export class StrapiService {
|
||||
|
||||
checkForUpdate = async () => {
|
||||
const { lastUpdate } = await getWebhookData()
|
||||
|
||||
if (this.lastUpdate < lastUpdate) {
|
||||
await this.clearCache()
|
||||
this.lastUpdate = lastUpdate
|
||||
}
|
||||
|
||||
setTimeout(() => this.checkForUpdate.bind(this), 5000)
|
||||
setTimeout(() => {
|
||||
this.checkForUpdate()
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
handleResponse = <T>(
|
||||
|
Loading…
x
Reference in New Issue
Block a user