({ context, initList = defaultInitList }: InitProps)
| 78 | } |
| 79 | |
| 80 | export const reinitialize = async ({ context, initList = defaultInitList }: InitProps) => { |
| 81 | const data = await initMemoryCache({ context, initList }) |
| 82 | // June 2023: we do not "warm" the cache from API app anymore, |
| 83 | // it is now the responsibility of each app to handle its own cache |
| 84 | // await initDbCache({ context, data, initList }) |
| 85 | |
| 86 | // However, we still inform the surveyform that a refresh is needed, via it's API |
| 87 | // TODO: in the future this could be made unnecessary if surveyform consumed the values set by the API more directly |
| 88 | try { |
| 89 | const surveyFormUrl = getEnvVar(EnvVar.SURVEYFORM_URL, { |
| 90 | hardFail: true, |
| 91 | default: DEFAULT_SURVEYFORM_URL, |
| 92 | calledFrom: 'reinitialize' |
| 93 | }) |
| 94 | const secretKey = getEnvVar(EnvVar.SECRET_KEY, { |
| 95 | hardFail: true, |
| 96 | calledFrom: 'reinitialize' |
| 97 | }) |
| 98 | // assuming API and surveyform use the same secret key for hooks |
| 99 | const resetUrl = `${surveyFormUrl}/api/cache/refresh-cache?key=${secretKey}&${initList |
| 100 | .map(item => encodeURIComponent(item)) |
| 101 | .join('&')}` |
| 102 | // NOTE: it's ok to log this secret key as it's already included in the URL, |
| 103 | // it's not used to secure any user data just to protect API calls from abuses |
| 104 | console.log('Resetting surveyform on URL:', resetUrl) |
| 105 | await fetch(resetUrl) |
| 106 | } catch (err) { |
| 107 | console.warn('Could not reinitialize surveyform cache:', err) |
| 108 | } |
| 109 | } |
no test coverage detected