Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jaeger UI broken when accessing via IPv6 address (#491) #494

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/jaeger-ui/src/utils/prefix-url.test.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

jest.mock('../site-prefix', () => `${global.location.origin}/a/site/prefix/`);

import prefixUrl from './prefix-url';
import prefixUrl, { getPathPrefix } from './prefix-url';

const PATH_PREFIX = '/a/site/prefix';

Expand All @@ -37,3 +37,25 @@ describe('prefixUrl()', () => {
});
});
});

describe('getPathPrefix()', () => {
const tests = [
{ address: '2a00:8a00:4000:751e::1c:8443' },
{ address: '[2a00:8a00:4000:751e::1c]:8443' },
{ address: '[2a00:8a00:4000:751e:0000:0000:0000:001c]:8443' },
{ address: '[::]:443' },
{ address: '127.0.0.1' },
{ address: '127.0.0.1:8443' },
{ address: 'jaeger.mydomain.com:8443' },
{ address: 'jaeger.mydomain.com' },
];

tests.forEach(({ address }) => {
it(`handles "${address}" correctly`, () => {
const origin = `https://${address}`;
const sitePrefix = `https://${address}/jaeger`;
const target = '/jaeger';
expect(getPathPrefix(origin, sitePrefix)).toBe(target);
});
});
});
12 changes: 10 additions & 2 deletions packages/jaeger-ui/src/utils/prefix-url.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sitePrefix from '../site-prefix';

const origin = process.env.NODE_ENV === 'test' ? global.location.origin : window.location.origin;

/**
* Generate the URL prefix from `sitePrefix` and use it for all subsequent calls
* to `prefixUrl()`. `sitePrefix` should be an absolute URL, e.g. with an origin.
Expand All @@ -24,8 +25,15 @@ const origin = process.env.NODE_ENV === 'test' ? global.location.origin : window
* - `"http://localhost:3000/abc/"` to `"/abc"`
* - `"http://localhost:3000/abc/def/"` to `"/abc/def"`
*/
const rx = new RegExp(`^${origin}|/$`, 'ig');
const pathPrefix = sitePrefix.replace(rx, '');
// exported for tests
export function getPathPrefix(orig?: string, sitePref?: string) {
everett980 marked this conversation as resolved.
Show resolved Hide resolved
const o = orig == null ? '' : orig.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
const s = sitePref == null ? '' : sitePref;
const rx = new RegExp(`^${o}|/$`, 'ig');
return s.replace(rx, '');
}

const pathPrefix = getPathPrefix(origin, sitePrefix);

/**
* Add the path prefix to the URL. See [site-prefix.js](../site-prefix.js) and
Expand Down