diff --git a/src/pages/api/services/proxy.js b/src/pages/api/services/proxy.js index dbe6fe9e3..7ac6772a3 100644 --- a/src/pages/api/services/proxy.js +++ b/src/pages/api/services/proxy.js @@ -55,6 +55,10 @@ export default async function handler(req, res) { req.query.endpoint = `${req.query.endpoint}?${query}`; } + if (mapping?.headers) { + req.extraHeaders = mapping.headers; + } + if (endpointProxy instanceof Function) { return endpointProxy(req, res, map); } diff --git a/src/utils/proxy/handlers/generic.js b/src/utils/proxy/handlers/generic.js index 91e0fa94f..ce1eba9bd 100644 --- a/src/utils/proxy/handlers/generic.js +++ b/src/utils/proxy/handlers/generic.js @@ -20,11 +20,10 @@ export default async function genericProxyHandler(req, res, map) { if (widget) { const url = new URL(formatApiCall(widgets[widget.type].api, { endpoint, ...widget })); - let headers; + const headers = req.extraHeaders ?? {}; + if (widget.username && widget.password) { - headers = { - Authorization: `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`, - }; + headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`; } const params = {