Skip to content

Commit

Permalink
getAbsoluteUrl have only 1 way to provide basePath
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Sep 18, 2020
1 parent 8e31474 commit db65847
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getAbsoluteUrlFactory } from './get_absolute_url';

const defaultOptions = {
defaultBasePath: 'sbp',
basePath: 'sbp',
protocol: 'http:',
hostname: 'localhost',
port: 5601,
Expand Down Expand Up @@ -64,8 +64,8 @@ test(`uses the provided hash with queryString`, () => {
});

test(`uses the provided basePath`, () => {
const getAbsoluteUrl = getAbsoluteUrlFactory(defaultOptions);
const absoluteUrl = getAbsoluteUrl({ basePath: '/s/marketing' });
const getAbsoluteUrl = getAbsoluteUrlFactory({ ...defaultOptions, basePath: '/s/marketing' });
const absoluteUrl = getAbsoluteUrl();
expect(absoluteUrl).toBe(`http://localhost:5601/s/marketing/app/kibana`);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import url from 'url';

interface AbsoluteURLFactoryOptions {
defaultBasePath: string;
basePath: string;
protocol: string;
hostname: string;
port: string | number;
Expand All @@ -17,14 +17,9 @@ export const getAbsoluteUrlFactory = ({
protocol,
hostname,
port,
defaultBasePath, // never gets an override
basePath,
}: AbsoluteURLFactoryOptions) => {
return function getAbsoluteUrl({
basePath = defaultBasePath, // unused
hash = '',
path = '/app/kibana',
search = '',
} = {}) {
return function getAbsoluteUrl({ hash = '', path = '/app/kibana', search = '' } = {}) {
return url.format({
protocol,
hostname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ export function getFullUrls<TaskPayloadType>({
config.get('kibanaServer', 'hostname'),
config.get('kibanaServer', 'port'),
] as string[];
const getAbsoluteUrl = getAbsoluteUrlFactory({
defaultBasePath: basePath,
protocol,
hostname,
port,
});
const getAbsoluteUrl = getAbsoluteUrlFactory({ basePath, protocol, hostname, port });

// PDF and PNG job params put in the url differently
let relativeUrls: string[] = [];
Expand Down
15 changes: 2 additions & 13 deletions x-pack/plugins/reporting/server/routes/diagnostic/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,8 @@ export const registerDiagnoseScreenshot = (reporting: ReportingCore, logger: Log
config.get('kibanaServer', 'port'),
] as string[];

const getAbsoluteUrl = getAbsoluteUrlFactory({
defaultBasePath: basePath,
protocol,
hostname,
port,
});

const hashUrl = getAbsoluteUrl({
basePath,
path: '/',
hash: '',
search: '',
});
const getAbsoluteUrl = getAbsoluteUrlFactory({ basePath, protocol, hostname, port });
const hashUrl = getAbsoluteUrl({ path: '/', hash: '', search: '' });

// Hack the layout to make the base/login page work
const layout = {
Expand Down

0 comments on commit db65847

Please sign in to comment.