fix: ensure only one instance of UnbodyService is created on the production env
This commit is contained in:
parent
3a645be467
commit
88026b71bb
|
@ -1576,20 +1576,22 @@ export class UnbodyService {
|
||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
|
||||||
const _globalThis = globalThis as any
|
|
||||||
if (!_globalThis.unbodyApi)
|
|
||||||
_globalThis.unbodyApi = new UnbodyService(
|
|
||||||
process.env.UNBODY_API_KEY || '',
|
|
||||||
process.env.UNBODY_PROJECT_ID || '',
|
|
||||||
)
|
|
||||||
|
|
||||||
const unbodyApi: UnbodyService =
|
const unbodyApi: UnbodyService =
|
||||||
process.env.NODE_ENV === 'development'
|
process.env.NODE_ENV === 'development'
|
||||||
? new UnbodyService(
|
? new UnbodyService(
|
||||||
process.env.UNBODY_API_KEY || '',
|
process.env.UNBODY_API_KEY || '',
|
||||||
process.env.UNBODY_PROJECT_ID || '',
|
process.env.UNBODY_PROJECT_ID || '',
|
||||||
)
|
)
|
||||||
: _globalThis.unbodyApi
|
: (() => {
|
||||||
|
const _globalThis = globalThis as any
|
||||||
|
if (!_globalThis.unbodyApi)
|
||||||
|
_globalThis.unbodyApi = new UnbodyService(
|
||||||
|
process.env.UNBODY_API_KEY || '',
|
||||||
|
process.env.UNBODY_PROJECT_ID || '',
|
||||||
|
)
|
||||||
|
|
||||||
|
return _globalThis.unbodyApi
|
||||||
|
})()
|
||||||
|
|
||||||
unbodyApi.onChange(async (oldData, data, changes, firstLoad) => {
|
unbodyApi.onChange(async (oldData, data, changes, firstLoad) => {
|
||||||
if (firstLoad || isBuildTime() || !sendDiscordNotifications) return
|
if (firstLoad || isBuildTime() || !sendDiscordNotifications) return
|
||||||
|
|
Loading…
Reference in New Issue