diff --git a/utils/api.js b/utils/api.js index d782cf63..a8e5695b 100644 --- a/utils/api.js +++ b/utils/api.js @@ -63,34 +63,29 @@ const fn = (cb, options = {}) => { }) : async (query) => logRuntime(() => addGeneratedTime(cb(query)), name, query, silenceParamsLog); - 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) + 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 ); - }) - .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)); - } - }) - ); - }; + res.status(code).json(formatJsonError(err)); + } + }) + ); apiCall.straightCall = callback;