Enhancement: allow widgets to specify default headers, fix buffer error output (#4287)

pull/4289/head
shamoon 1 week ago committed by GitHub
parent 535be37bef
commit d82fbc3026
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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")}`;
@ -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);

Loading…
Cancel
Save