(req: Request, res: Response, func: () => Promise<void>)
| 82 | * @param func |
| 83 | */ |
| 84 | const checkSecretKey = async (req: Request, res: Response, func: () => Promise<void>) => { |
| 85 | const secretKey = getEnvVar(EnvVar.SECRET_KEY, { |
| 86 | hardFail: true, |
| 87 | calledFrom: 'checkSecretKey' |
| 88 | }) |
| 89 | if (req?.query?.key !== secretKey) { |
| 90 | // throw new Error('Authorization error') |
| 91 | res.status(401).send('Not authorized') |
| 92 | } else { |
| 93 | await func() |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | // if SURVEYS_URL is defined, then use that to load surveys; |
| 98 | // if not, look in local filesystem |