mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-13 16:54:43 +02:00
⚡ Adds support for custom headers, body and method in widgt request object
This commit is contained in:
parent
9cd8c21d8e
commit
2c9ae46207
@ -98,16 +98,20 @@ const WidgetMixin = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
/* Makes data request, returns promise */
|
/* Makes data request, returns promise */
|
||||||
makeRequest(endpoint, options) {
|
makeRequest(endpoint, options, protocol, body) {
|
||||||
// Request Options
|
// Request Options
|
||||||
const method = 'GET';
|
const method = protocol || 'GET';
|
||||||
const url = this.useProxy ? this.proxyReqEndpoint : endpoint;
|
const url = this.useProxy ? this.proxyReqEndpoint : endpoint;
|
||||||
const CustomHeaders = options ? JSON.stringify(options) : null;
|
const data = JSON.stringify(body || {});
|
||||||
|
const CustomHeaders = options || null;
|
||||||
const headers = this.useProxy
|
const headers = this.useProxy
|
||||||
? { 'Target-URL': endpoint, CustomHeaders } : CustomHeaders;
|
? { 'Target-URL': endpoint, CustomHeaders: JSON.stringify(CustomHeaders) } : CustomHeaders;
|
||||||
|
const requestConfig = {
|
||||||
|
method, url, headers, data,
|
||||||
|
};
|
||||||
// Make request
|
// Make request
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.request({ method, url, headers })
|
axios.request(requestConfig)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.data.success === false) {
|
if (response.data.success === false) {
|
||||||
this.error('Proxy returned error from target server', response.data.message);
|
this.error('Proxy returned error from target server', response.data.message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user