mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
When generating the pubdash url, use the base url from the Grafana config. This allows the url generation to work in the case that Grafana is hosted on a subpath. (#55204)
Support subpaths when generating public dashboard url
This commit is contained in:
parent
00e7324bf6
commit
5121e32722
@ -1,5 +1,7 @@
|
|||||||
import { VariableModel } from 'app/features/variables/types';
|
import { VariableModel } from 'app/features/variables/types';
|
||||||
|
|
||||||
|
import { updateConfig } from '../../../../core/config';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
PublicDashboard,
|
PublicDashboard,
|
||||||
dashboardHasTemplateVariables,
|
dashboardHasTemplateVariables,
|
||||||
@ -23,9 +25,13 @@ describe('dashboardHasTemplateVariables', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('generatePublicDashboardUrl', () => {
|
describe('generatePublicDashboardUrl', () => {
|
||||||
it('has the right uid', () => {
|
it('uses the grafana config appUrl to generate the url', () => {
|
||||||
let pubdash = { accessToken: 'abcd1234' } as PublicDashboard;
|
const appUrl = 'http://localhost/';
|
||||||
expect(generatePublicDashboardUrl(pubdash)).toEqual(`${window.location.origin}/public-dashboards/abcd1234`);
|
const accessToken = 'abcd1234';
|
||||||
|
updateConfig({ appUrl });
|
||||||
|
let pubdash = { accessToken } as PublicDashboard;
|
||||||
|
|
||||||
|
expect(generatePublicDashboardUrl(pubdash)).toEqual(`${appUrl}public-dashboards/${accessToken}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { getBackendSrv } from '@grafana/runtime';
|
import { getBackendSrv } from '@grafana/runtime';
|
||||||
import { notifyApp } from 'app/core/actions';
|
import { notifyApp } from 'app/core/actions';
|
||||||
|
import { getConfig } from 'app/core/config';
|
||||||
import { createSuccessNotification } from 'app/core/copy/appNotification';
|
import { createSuccessNotification } from 'app/core/copy/appNotification';
|
||||||
import { VariableModel } from 'app/features/variables/types';
|
import { VariableModel } from 'app/features/variables/types';
|
||||||
import { dispatch } from 'app/store/store';
|
import { dispatch } from 'app/store/store';
|
||||||
@ -61,6 +62,14 @@ export const publicDashboardPersisted = (publicDashboard: PublicDashboard): bool
|
|||||||
return publicDashboard.uid !== '' && publicDashboard.uid !== undefined;
|
return publicDashboard.uid !== '' && publicDashboard.uid !== undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the public dashboard url. Uses the appUrl from the Grafana boot config, so urls will also be correct
|
||||||
|
* when Grafana is hosted on a subpath.
|
||||||
|
*
|
||||||
|
* All app urls from the Grafana boot config end with a slash.
|
||||||
|
*
|
||||||
|
* @param publicDashboard
|
||||||
|
*/
|
||||||
export const generatePublicDashboardUrl = (publicDashboard: PublicDashboard): string => {
|
export const generatePublicDashboardUrl = (publicDashboard: PublicDashboard): string => {
|
||||||
return `${window.location.origin}/public-dashboards/${publicDashboard.accessToken}`;
|
return `${getConfig().appUrl}public-dashboards/${publicDashboard.accessToken}`;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user