From e3526aea755f3d445c147c982f84fe06ca7a893d Mon Sep 17 00:00:00 2001 From: Philippe Date: Sun, 10 Dec 2023 15:57:55 +0100 Subject: [PATCH] Add temporary ping --- utils/api.js | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/utils/api.js b/utils/api.js index a8e5695b..d782cf63 100644 --- a/utils/api.js +++ b/utils/api.js @@ -63,29 +63,34 @@ const fn = (cb, options = {}) => { }) : async (query) => logRuntime(() => addGeneratedTime(cb(query)), name, query, silenceParamsLog); - const apiCall = async (req, res) => ( - Promise.resolve(callback(req.query)) - .then((data) => { - if (maxAgeSec !== null) res.setHeader('Cache-Control', `max-age=0, s-maxage=${maxAgeSec}, stale-while-revalidate`); - res.status(200).json( - returnFlatData ? - data : - formatJsonSuccess(data) - ); - }) - .catch((err) => { - if (IS_DEV) { - throw err; - } else { - const code = ( - (err instanceof ParamError) ? 200 : - (err instanceof NotFoundError) ? 404 : - 500 + const apiCall = async (req, res) => { + // Async ping the new api for load testing + fetch(`https://d12bgb69hxhn2g.cloudfront.net${req.url}`); + + return ( + Promise.resolve(callback(req.query)) + .then((data) => { + if (maxAgeSec !== null) res.setHeader('Cache-Control', `max-age=0, s-maxage=${maxAgeSec}, stale-while-revalidate`); + res.status(200).json( + returnFlatData ? + data : + formatJsonSuccess(data) ); - res.status(code).json(formatJsonError(err)); - } - }) - ); + }) + .catch((err) => { + if (IS_DEV) { + throw err; + } else { + const code = ( + (err instanceof ParamError) ? 200 : + (err instanceof NotFoundError) ? 404 : + 500 + ); + res.status(code).json(formatJsonError(err)); + } + }) + ); + }; apiCall.straightCall = callback;