From 2c9ae46207e6f38b2a69e18ddf7943cb9f974fed Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Fri, 21 Jan 2022 13:01:33 +0000 Subject: [PATCH] :zap: Adds support for custom headers, body and method in widgt request object --- src/mixins/WidgetMixin.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mixins/WidgetMixin.js b/src/mixins/WidgetMixin.js index e5ebeded..53dfc5ef 100644 --- a/src/mixins/WidgetMixin.js +++ b/src/mixins/WidgetMixin.js @@ -98,16 +98,20 @@ const WidgetMixin = { }; }, /* Makes data request, returns promise */ - makeRequest(endpoint, options) { + makeRequest(endpoint, options, protocol, body) { // Request Options - const method = 'GET'; + const method = protocol || 'GET'; 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 - ? { 'Target-URL': endpoint, CustomHeaders } : CustomHeaders; + ? { 'Target-URL': endpoint, CustomHeaders: JSON.stringify(CustomHeaders) } : CustomHeaders; + const requestConfig = { + method, url, headers, data, + }; // Make request return new Promise((resolve, reject) => { - axios.request({ method, url, headers }) + axios.request(requestConfig) .then((response) => { if (response.data.success === false) { this.error('Proxy returned error from target server', response.data.message);