Skip to content

Commit

Permalink
Enhancement: allow widgets to specify default headers, fix buffer err…
Browse files Browse the repository at this point in the history
…or output (#4287)
  • Loading branch information
shamoon authored Nov 13, 2024
1 parent 535be37 commit d82fbc3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/proxy/handlers/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default async function genericProxyHandler(req, res, map) {
formatApiCall(widgets[widget.type].api, { endpoint, ...widget }).replace(/(?<=\?.*)\?/g, "&"),
);

const headers = req.extraHeaders ?? widget.headers ?? {};
const headers = req.extraHeaders ?? widget.headers ?? widgets[widget.type].headers ?? {};

if (widget.username && widget.password) {
headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`;
Expand Down Expand Up @@ -75,7 +75,13 @@ export default async function genericProxyHandler(req, res, map) {
url.port ? `:${url.port}` : "",
url.pathname,
);
return res.status(status).json({ error: { message: "HTTP Error", url: sanitizeErrorURL(url), resultData } });
return res.status(status).json({
error: {
message: "HTTP Error",
url: sanitizeErrorURL(url),
resultData: Buffer.isBuffer(resultData) ? Buffer.from(resultData).toString() : resultData,
},
});
}

return res.status(status).send(resultData);
Expand Down

0 comments on commit d82fbc3

Please sign in to comment.