This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 279
/
utils.js
54 lines (47 loc) · 1.51 KB
/
utils.js
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
53
54
import {contains} from 'ramda';
export function dynamicRequireElectron() {
return window.require('electron');
}
export function baseUrl() {
/*
* Return the base URL of the app.
* If the user is running this app locally and is configuring their database,
* then they will be at https://their-subdomain.plot.ly/database-connector
* and this function will return https://their-subdomain.plot.ly
* If the user is on on-prem, then the connector is prefixed behind
* /external-data-connector, so they will be configuring their connections at
* https://plotly.acme.com/external-data-connector/database-connector and this function
* will return https://plotly.acme.com/external-data-connector/
*/
let url = window.location.href;
if (url.endsWith('/')) {
url = url.slice(0, url.length - 1);
}
if (url.endsWith('database-connector')) {
url = url.slice(0, url.length - 'database-connector'.length);
}
return url;
}
export function usesHttpsProtocol() {
return contains('https://', baseUrl());
}
export function isOnPrem() {
return (contains('external-data-connector', baseUrl()));
}
export function plotlyUrl() {
if (isOnPrem()) {
return window.location.origin;
}
return 'https://plot.ly';
}
export function isElectron() {
return window.process && window.process.type === 'renderer';
}
export function homeUrl() {
if (isOnPrem()) {
return '/external-data-connector';
}
else {
return '';
}
}