@fleetbase/ember-core 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addon/utils/console-url.js +22 -38
- package/package.json +1 -1
|
@@ -2,55 +2,39 @@ import config from '@fleetbase/console/config/environment';
|
|
|
2
2
|
import { isBlank } from '@ember/utils';
|
|
3
3
|
|
|
4
4
|
const isDevelopment = ['local', 'development'].includes(config.environment);
|
|
5
|
-
const isProduction = ['production'].includes(config.environment);
|
|
6
5
|
|
|
7
|
-
function queryString(params) {
|
|
6
|
+
export function queryString(params) {
|
|
8
7
|
return Object.keys(params)
|
|
9
|
-
.map((key) => `${key}=${params[key]}`)
|
|
8
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
|
10
9
|
.join('&');
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
function extractHostAndPort(url) {
|
|
12
|
+
export function extractHostAndPort(url) {
|
|
14
13
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const port = parsedUrl.port;
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
host: host,
|
|
21
|
-
port: port || null,
|
|
22
|
-
};
|
|
14
|
+
const { hostname: host, port = null } = new URL(url);
|
|
15
|
+
return { host, port };
|
|
23
16
|
} catch (error) {
|
|
24
|
-
|
|
25
|
-
return null;
|
|
17
|
+
return { host: null, port: null };
|
|
26
18
|
}
|
|
27
19
|
}
|
|
28
20
|
|
|
29
|
-
export default function consoleUrl(path = '', queryParams = {}, subdomain =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!isProduction && !isDevelopment) {
|
|
40
|
-
url += `${config.environment}.`;
|
|
21
|
+
export default function consoleUrl(path = '', queryParams = {}, subdomain = null, host = null) {
|
|
22
|
+
if (subdomain === null || host === null) {
|
|
23
|
+
const { hostname, host: currentHost } = window.location;
|
|
24
|
+
if (subdomain === null) {
|
|
25
|
+
const parts = hostname.split('.');
|
|
26
|
+
subdomain = parts.length > 2 ? parts[0] : null;
|
|
27
|
+
}
|
|
28
|
+
if (host === null) {
|
|
29
|
+
host = currentHost;
|
|
30
|
+
}
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
url += `/${path}`;
|
|
50
|
-
|
|
51
|
-
if (urlParams) {
|
|
52
|
-
url += `?${urlParams}`;
|
|
53
|
-
}
|
|
33
|
+
const { host: parsedHost, port } = extractHostAndPort(host);
|
|
34
|
+
const protocol = isDevelopment ? 'http://' : 'https://';
|
|
35
|
+
const urlParams = !isBlank(queryParams) ? queryString(queryParams) : '';
|
|
36
|
+
const portSegment = port ? `:${port}` : '';
|
|
37
|
+
const pathSegment = path.startsWith('/') ? path : `/${path}`;
|
|
54
38
|
|
|
55
|
-
return
|
|
39
|
+
return `${protocol}${subdomain ? subdomain + '.' : ''}${parsedHost}${portSegment}${pathSegment}${urlParams ? '?' + urlParams : ''}`;
|
|
56
40
|
}
|
package/package.json
CHANGED