Skip to content

Commit

Permalink
Add temporary ping
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe-git committed Dec 10, 2023
1 parent 388fe9e commit e3526ae
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

1 comment on commit e3526ae

@vercel
Copy link

@vercel vercel bot commented on e3526ae Dec 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.