Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Commit edab064

Browse files
committed
add route for proxy
1 parent 13edb2c commit edab064

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/datasource.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ import { getTemplateSrv } from '@grafana/runtime';
1616

1717
import { MyQuery, MyDataSourceOptions, defaultQuery } from './types';
1818

19+
// proxy route
20+
const routePath = '/nodegraphds';
21+
1922
export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
20-
baseUrl: string; // base url of the api
23+
url: string;
2124
constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
2225
super(instanceSettings);
2326

24-
this.baseUrl = instanceSettings.jsonData.baseUrl || '';
27+
// proxy url
28+
this.url = instanceSettings.url || '';
2529
}
2630

2731
async query(options: DataQueryRequest<MyQuery>): Promise<DataQueryResponse> {
@@ -98,13 +102,11 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
98102
return Promise.all(promises).then(data => ({ data: data[0] }));
99103
}
100104
async doRequest(endpoint: string, params?: string) {
101-
// const result = await getBackendSrv().datasourceRequest({
102-
// method: 'GET',
103-
// url: `${this.baseUrl}${endpoint}${`?${params}`}`,
104-
// });
105+
// Do the request on proxy; the server will replace url + routePath with the url
106+
// defined in plugin.json
105107
const result = getBackendSrv().datasourceRequest({
106108
method: 'GET',
107-
url: `${this.baseUrl}${endpoint}${params?.length ? `?${params}` : ''}`,
109+
url: `${this.url}${routePath}${endpoint}${params?.length ? `?${params}` : ''}`,
108110
});
109111
return result;
110112
}

src/plugin.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/grafana/grafana/master/docs/sources/developers/plugins/plugin.schema.json",
3+
"routes": [
4+
{
5+
"path": "nodegraphds",
6+
"url": "{{ .JsonData.baseUrl }}"
7+
}
8+
],
39
"type": "datasource",
410
"name": "Node Graph API",
511
"id": "hamedkarbasi93-nodegraphapi-datasource",

0 commit comments

Comments
 (0)