-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathconstants.js
More file actions
60 lines (53 loc) · 1.75 KB
/
constants.js
File metadata and controls
60 lines (53 loc) · 1.75 KB
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
55
56
57
58
59
60
export const CON_ORIGIN = 'https://content.da.live';
export const AEM_ORIGIN = 'https://admin.hlx.page';
export const SUPPORTED_FILES = {
html: 'text/html',
jpeg: 'image/jpeg',
json: 'application/json',
jpg: 'image/jpeg',
png: 'image/png',
gif: 'image/gif',
mp4: 'video/mp4',
pdf: 'application/pdf',
svg: 'image/svg+xml',
ico: 'image/x-icon',
};
const DA_ADMIN_ENVS = {
local: 'http://localhost:8787',
stage: 'https://stage-admin.da.live',
prod: 'https://admin.da.live',
};
const DA_COLLAB_ENVS = {
local: 'ws://localhost:4711',
stage: 'wss://stage-collab.da.live',
prod: 'wss://collab.da.live',
};
// HTTP versions of collab endpoints for REST API calls (convert API)
const DA_COLLAB_HTTP_ENVS = {
local: 'http://localhost:4711',
stage: 'https://stage-collab.da.live',
prod: 'https://collab.da.live',
};
function getDaEnv(location, key, envs) {
const { href } = location;
const query = new URL(href).searchParams.get(key);
if (query && query === 'reset') {
localStorage.removeItem(key);
} else if (query) {
localStorage.setItem(key, query);
}
const env = envs[localStorage.getItem(key) || 'prod'];
// TODO: INFRA
return location.origin === 'https://da.page' ? env.replace('.live', '.page') : env;
}
export const getDaAdmin = (() => {
let daAdmin;
return (location) => {
if (!location && daAdmin) return daAdmin;
daAdmin = getDaEnv(location || window.location, 'da-admin', DA_ADMIN_ENVS);
return daAdmin;
};
})();
export const DA_ORIGIN = (() => getDaEnv(window.location, 'da-admin', DA_ADMIN_ENVS))();
export const COLLAB_ORIGIN = (() => getDaEnv(window.location, 'da-collab', DA_COLLAB_ENVS))();
export const COLLAB_HTTP_ORIGIN = (() => getDaEnv(window.location, 'da-collab', DA_COLLAB_HTTP_ENVS))();