Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ› Apply custom headers to fetch request (#1549)

Alicia Sykese970fc69c166
diff --git a/src/mixins/WidgetMixin.js b/src/mixins/WidgetMixin.js
index e183000b..507eaacc 100644
--- a/src/mixins/WidgetMixin.js
+++ b/src/mixins/WidgetMixin.js
@@ -105,10 +105,18 @@ const WidgetMixin = {
const method = protocol || 'GET';
const url = this.useProxy ? this.proxyReqEndpoint : endpoint;
const data = JSON.stringify(body || {});
+
const CustomHeaders = options || {};
- const headers = new Headers(this.useProxy
- ? ({ ...CustomHeaders, 'Target-URL': endpoint })
- : CustomHeaders);
+ const headers = new Headers();
+
+ // 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
const bodyContent = method.toUpperCase() === 'GET' ? undefined : data;