diff --git a/web/ui/react-app/src/hooks/useFetch.ts b/web/ui/react-app/src/hooks/useFetch.ts index 7272e87ef..2f2fc92a7 100644 --- a/web/ui/react-app/src/hooks/useFetch.ts +++ b/web/ui/react-app/src/hooks/useFetch.ts @@ -17,7 +17,7 @@ export const useFetch = (url: string, options?: RequestInit): Fetc const fetchData = async () => { setIsLoading(true); try { - const res = await fetch(url, options); + const res = await fetch(url, { cache: 'no-cache', credentials: 'same-origin', ...options }); if (!res.ok) { throw new Error(res.statusText); } diff --git a/web/ui/react-app/src/pages/graph/Panel.tsx b/web/ui/react-app/src/pages/graph/Panel.tsx index 5e1970129..17874ea95 100644 --- a/web/ui/react-app/src/pages/graph/Panel.tsx +++ b/web/ui/react-app/src/pages/graph/Panel.tsx @@ -130,7 +130,11 @@ class Panel extends Component { throw new Error('Invalid panel type "' + this.props.options.type + '"'); } - fetch(`${this.props.pathPrefix}${path}?${params}`, { cache: 'no-store', signal: abortController.signal }) + fetch(`${this.props.pathPrefix}${path}?${params}`, { + cache: 'no-store', + credentials: 'same-origin', + signal: abortController.signal, + }) .then(resp => resp.json()) .then(json => { if (json.status !== 'success') { diff --git a/web/ui/react-app/src/pages/graph/PanelList.tsx b/web/ui/react-app/src/pages/graph/PanelList.tsx index 8e2cec688..706f13567 100644 --- a/web/ui/react-app/src/pages/graph/PanelList.tsx +++ b/web/ui/react-app/src/pages/graph/PanelList.tsx @@ -34,7 +34,7 @@ class PanelList extends Component { if (resp.ok) { return resp.json(); @@ -48,7 +48,7 @@ class PanelList extends Component this.setState({ fetchMetricsError: error.message })); const browserTime = new Date().getTime() / 1000; - fetch(`${this.props.pathPrefix}/api/v1/query?query=time()`, { cache: 'no-store' }) + fetch(`${this.props.pathPrefix}/api/v1/query?query=time()`, { cache: 'no-store', credentials: 'same-origin' }) .then(resp => { if (resp.ok) { return resp.json(); diff --git a/web/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx b/web/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx index 0da9a7b29..de705de95 100644 --- a/web/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx +++ b/web/ui/react-app/src/pages/targets/ScrapePoolList.test.tsx @@ -55,7 +55,7 @@ describe('Flags', () => { scrapePoolList = mount(); }); scrapePoolList.update(); - expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', undefined); + expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', { cache: 'no-cache', credentials: 'same-origin' }); const panels = scrapePoolList.find(ScrapePoolPanel); expect(panels).toHaveLength(3); const activeTargets: Target[] = sampleApiResponse.data.activeTargets as Target[]; @@ -74,7 +74,7 @@ describe('Flags', () => { scrapePoolList = mount(); }); scrapePoolList.update(); - expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', undefined); + expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', { cache: 'no-cache', credentials: 'same-origin' }); const panels = scrapePoolList.find(ScrapePoolPanel); expect(panels).toHaveLength(0); }); @@ -90,7 +90,7 @@ describe('Flags', () => { }); scrapePoolList.update(); - expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', undefined); + expect(mock).toHaveBeenCalledWith('../api/v1/targets?state=active', { cache: 'no-cache', credentials: 'same-origin' }); const alert = scrapePoolList.find(Alert); expect(alert.prop('color')).toBe('danger'); expect(alert.text()).toContain('Error fetching targets'); diff --git a/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx b/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx index f19994025..737e89493 100644 --- a/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx +++ b/web/ui/react-app/src/pages/tsdbStatus/TSDBStatus.test.tsx @@ -66,7 +66,10 @@ describe('TSDB Stats', () => { }); page.update(); - expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', undefined); + expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', { + cache: 'no-cache', + credentials: 'same-origin', + }); const alert = page.find(Alert); expect(alert.prop('color')).toBe('danger'); expect(alert.text()).toContain('error loading tsdb status'); @@ -101,7 +104,10 @@ describe('TSDB Stats', () => { }); page.update(); - expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', undefined); + expect(mock).toHaveBeenCalledWith('/path/prefix/api/v1/status/tsdb', { + cache: 'no-cache', + credentials: 'same-origin', + }); for (let i = 0; i < tables.length; i++) { const data = tables[i].data;