mirror of https://github.com/Lissy93/dashy.git
🐛 Apply custom headers to fetch request (#1549)
This commit is contained in:
parent
83059bc536
commit
e970fc69c1
|
@ -105,10 +105,18 @@ const WidgetMixin = {
|
||||||
const method = protocol || 'GET';
|
const method = protocol || 'GET';
|
||||||
const url = this.useProxy ? this.proxyReqEndpoint : endpoint;
|
const url = this.useProxy ? this.proxyReqEndpoint : endpoint;
|
||||||
const data = JSON.stringify(body || {});
|
const data = JSON.stringify(body || {});
|
||||||
|
|
||||||
const CustomHeaders = options || {};
|
const CustomHeaders = options || {};
|
||||||
const headers = new Headers(this.useProxy
|
const headers = new Headers();
|
||||||
? ({ ...CustomHeaders, 'Target-URL': endpoint })
|
|
||||||
: CustomHeaders);
|
// If using a proxy, set the 'Target-URL' header
|
||||||
|
if (this.useProxy) {
|
||||||
|
headers.append('Target-URL', endpoint);
|
||||||
|
}
|
||||||
|
// Apply widget-specific custom headers
|
||||||
|
Object.entries(CustomHeaders).forEach(([key, value]) => {
|
||||||
|
headers.append(key, value);
|
||||||
|
});
|
||||||
|
|
||||||
// If the request is a GET, delete the body
|
// If the request is a GET, delete the body
|
||||||
const bodyContent = method.toUpperCase() === 'GET' ? undefined : data;
|
const bodyContent = method.toUpperCase() === 'GET' ? undefined : data;
|
||||||
|
|
Loading…
Reference in New Issue