🎇 Updates widget request to only apply headers when needed

🎇 Happy New Year 🎇
This commit is contained in:
Alicia Sykes 2021-12-31 23:59:14 +00:00
parent 1914d25b45
commit 395aea292e
1 changed files with 9 additions and 3 deletions

View File

@ -16,6 +16,7 @@ const WidgetMixin = {
}, },
data: () => ({ data: () => ({
progress: new ProgressBar({ color: 'var(--progress-bar)' }), progress: new ProgressBar({ color: 'var(--progress-bar)' }),
overrideProxyChoice: false,
}), }),
/* When component mounted, fetch initial data */ /* When component mounted, fetch initial data */
mounted() { mounted() {
@ -27,7 +28,7 @@ const WidgetMixin = {
return `${baseUrl}${serviceEndpoints.corsProxy}`; return `${baseUrl}${serviceEndpoints.corsProxy}`;
}, },
useProxy() { useProxy() {
return this.options.useProxy; return this.options.useProxy || this.overrideProxyChoice;
}, },
}, },
methods: { methods: {
@ -60,15 +61,20 @@ const WidgetMixin = {
return { content, trigger: 'hover focus', delay: 250 }; return { content, trigger: 'hover focus', delay: 250 };
}, },
/* Makes data request, returns promise */ /* Makes data request, returns promise */
makeRequest(endpoint, options = {}) { makeRequest(endpoint, options) {
// Request Options // Request Options
const method = 'GET'; const method = 'GET';
const url = this.useProxy ? this.proxyReqEndpoint : endpoint; const url = this.useProxy ? this.proxyReqEndpoint : endpoint;
const headers = this.useProxy ? { 'Target-URL': endpoint, ...options } : options; const CustomHeaders = options ? { ...JSON.stringify(options) } : null;
const headers = this.useProxy
? { 'Target-URL': endpoint, CustomHeaders } : CustomHeaders;
// Make request // Make request
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.request({ method, url, headers }) axios.request({ method, url, headers })
.then((response) => { .then((response) => {
if (response.data.success === false) {
this.error('Proxy returned error from target server', response.data.message);
}
resolve(response.data); resolve(response.data);
}) })
.catch((dataFetchError) => { .catch((dataFetchError) => {