I am building a grafana panel plugin. I have a backend (not grafana backend) runnning at port 8080 and I want to fetch some data from it. Something like the code below
async function fetchAgents(): Promise<string[]> {
try {
const url = '/api/agents';
const response = await getBackendSrv().get<string[]>(url);
return response;
} catch (error) {
console.error('Failed to fetch agents:', error);
if (error instanceof Error) {
throw new Error(error.message || 'Failed to fetch agents');
} else {
throw new Error('Failed to fetch agents');
}
}
}
Now I want to route this. I thought you can rout by specifying routes in plugin.json
like
"routes": [
{
"path": "/api/agents",
"url": "http://backend-app:8080/api/agents"
},
{
"path": "/api/set_agent",
"url": "http://backend-app:8080/api/set_agent"
}
]
I am not sure if this is enough or no? And what endpoint should I make the call to fetch the data. I am making call at the endpoint below but there is no response.
const url = '/api/plugins/faib-dynotrace-panel/resources/api/agents';
const response = await getBackendSrv().get<string[]>(url);
Can someone explain how can I route this correctly or routing is possible at all? I am very grateful for any help.