Skip to content

Commit 689f4c8

Browse files
MattIPv4ifrost
andauthored
feat: switch cloud-home-app plugin proxy usage to own (#579)
* Switch cloud-home-app plugin proxy usage to own * Only make grafanacom-api fetch call when in Cloud --------- Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
1 parent 0191130 commit 689f4c8

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

src/app/components/Onboarding/domain/useOnboardingModal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { useState } from 'react';
44
import { useFetchInstances } from '../infrastructure/useFetchInstances';
55

66
export function useOnboardingModal(): DomainHookReturnValue {
7-
const { instances } = useFetchInstances();
8-
97
const [settingsUrl, setSettingsUrl] = useState('https://grafana.com/auth/sign-in/');
10-
const isCloud = /grafana(-dev|-ops)?\.net/.test(window.location.host);
8+
9+
const isCloud = /\.grafana(-dev|-ops)?\.net$/.test(window.location.host);
10+
const { instances } = useFetchInstances(isCloud);
1111

1212
if (instances && instances.orgSlug && instances.hpInstanceId) {
1313
const newSettingsUrl = `https://grafana.com/orgs/${instances.orgSlug}/hosted-profiles/${instances.hpInstanceId}`;

src/app/components/Onboarding/infrastructure/useFetchInstances.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { useQuery } from '@tanstack/react-query';
2+
import { PLUGIN_API_URL } from 'src/constants';
23

3-
export function useFetchInstances() {
4+
export function useFetchInstances(enabled = true) {
45
const { isFetching, error, data } = useQuery({
6+
enabled,
57
queryKey: ['instances'],
68
queryFn: () =>
7-
fetch('/api/plugin-proxy/cloud-home-app/grafanacom-api/instances').then((response) => response.json()),
9+
fetch(`${PLUGIN_API_URL}/grafanacom-api/instances`).then((response) => response.json()),
810
});
911

1012
return {

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import plugin from './plugin.json';
33
export const PYROSCOPE_APP_ID = plugin.id;
44

55
export const PLUGIN_BASE_URL = `/a/${PYROSCOPE_APP_ID}`;
6+
export const PLUGIN_API_URL = `/api/plugin-proxy/${PYROSCOPE_APP_ID}`;
67

78
export enum ROUTES {
89
EXPLORE = '/explore',

src/plugin.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,18 @@
7979
]
8080
}
8181
]
82-
}
82+
},
83+
"routes": [
84+
{
85+
"path": "/grafanacom-api/instances",
86+
"method": "GET",
87+
"url": "{{.SecureJsonData.gcomApiUrl}}/instances/{{.SecureJsonData.stackId}}",
88+
"headers": [
89+
{
90+
"name": "Authorization",
91+
"content": "Bearer {{.SecureJsonData.gcomApiToken}}"
92+
}
93+
]
94+
}
95+
]
8396
}

0 commit comments

Comments
 (0)