-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (36 loc) · 1.05 KB
/
index.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
// currently not-used, only index.html is (this is for the vite.js setup)
import "./index.css";
import r4 from "@radio4000/components";
import "@radio4000/components/style";
/* App config
- get the public environment config from a json file,
- set it on the app's custom-element
- append the app as the only element of the body's DOM
*/
const containerElementName = "body";
const appElementName = "r4-app";
/* customElements.define(appElementName, r4.R4App) */
const $app = document.createElement(appElementName);
fetch("/.env.json")
.then(async (data) => {
let config = {};
try {
config = await data.json();
} catch (e) {
/* console.info('.env.json config file not found') */
}
return config;
})
.then((config) => {
Object.entries(config).forEach(([key, value]) => {
if (typeof value === "object") {
$app.setAttribute(key, JSON.stringify(value));
} else {
$app.setAttribute(key, value);
}
});
})
.finally(() => {
document.querySelector(containerElementName).append($app);
/* console.info(`${appElementName} loaded`) */
});