/
url-helper.ts
52 lines (43 loc) · 1.37 KB
/
url-helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { defaultThemeMode, type ThemeMode } from '@axonivy/inscription-editor';
export namespace URLParams {
export function parameter(key: string): string | undefined {
const param = new URLSearchParams(window.location.search).get(key);
return param !== null ? decodeURIComponent(param) : undefined;
}
export function app(): string {
return parameter('app') ?? '';
}
export function pmv(): string {
return parameter('pmv') ?? '';
}
export function pid(): string {
return parameter('pid') ?? '';
}
export function webSocketBase(): string {
return `${isSecureConnection() ? 'wss' : 'ws'}://${server()}`;
}
export function themeMode(): ThemeMode {
return (parameter('theme') as ThemeMode) ?? defaultThemeMode();
}
const isSecureConnection = () => {
const secureParam = parameter('secure');
if (secureParam === 'true') {
return true;
}
if (secureParam === 'false') {
return false;
}
return window.location.protocol === 'https:';
};
const server = () => {
return parameter('server') ?? basePath();
};
const basePath = () => {
const protocol = window.location.protocol;
const href = window.location.href;
if (href.includes('/process-inscription')) {
return href.substring(protocol.length + 2, href.indexOf('/process-inscription'));
}
return 'localhost:8081';
};
}