From fdfb5c5770fef241118c8c348cb37262b87605cf Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sat, 10 Mar 2018 23:47:12 +0300 Subject: [PATCH] add support for setting site-id in fetcher --- web/app/common/fetcher.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/web/app/common/fetcher.js b/web/app/common/fetcher.js index 675384f6..777d8a74 100644 --- a/web/app/common/fetcher.js +++ b/web/app/common/fetcher.js @@ -1,6 +1,7 @@ import 'common/promises'; -// TODO: i think we need to use unfetch here instead of heavy axios +// TODO: i've tried to rewrite it to unfetch but it wasn't easy to make it work +// we need to try again later import axios from 'axios'; import { BASE_URL, API_BASE } from './constants'; @@ -27,6 +28,7 @@ methods.forEach(method => { body = {}, withCredentials = false, overriddenApiBase = API_BASE, + siteId = siteId, } = (typeof data === 'string' ? { url: data } : data); const basename = `${BASE_URL}${overriddenApiBase}`; @@ -47,7 +49,11 @@ methods.forEach(method => { } parameters.url = `${basename}${url}`; - if (method !== 'post') parameters.url += (parameters.url.includes('?') ? '&' : '?') + `site=${siteId}`; + + if (method !== 'post' && !parameters.url.includes('?site=') && !parameters.url.includes('&site=')) { + parameters.url += (parameters.url.includes('?') ? '&' : '?') + `site=${siteId}`; + } + parameters.cancelToken = new CancelToken(executor => { cancelHandler.push({ executor,