consolidate api handlers

This commit is contained in:
Ben Phelps 2022-09-12 10:59:56 +03:00
parent 7bf1bf5369
commit 3660140539
3 changed files with 14 additions and 40 deletions

View file

@ -10,14 +10,22 @@ export default async function credentialedProxyHandler(req, res) {
if (widget) {
const url = new URL(formatApiCall(widget.type, { endpoint, ...widget }));
const headers = {
"Content-Type": "application/json",
};
if (widget.type === "coinmarketcap") {
headers["X-CMC_PRO_API_KEY"] = `${widget.key}`;
} else {
headers["X-API-Key"] = `${widget.key}`;
}
const [status, contentType, data] = await httpProxy(url, {
method: req.method,
withCredentials: true,
credentials: "include",
headers: {
"X-API-Key": `${widget.key}`,
"Content-Type": "application/json",
},
headers,
});
if (status === 204 || status === 304) {