-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
main.js
43 lines (35 loc) · 970 Bytes
/
main.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
import App from './App.svelte';
import ErrorPage from './ErrorPage.svelte';
import CuteConfig from './lib/cuteConfig';
async function app() {
const root = document.getElementById('app');
const rootPath = root.getAttribute('data-root') || '';
const url = process.env.NODE_ENV === 'demo'
? '/insomnia-documenter/insomnia.json'
: `${rootPath}/insomnia.json`;
window.INSOMNIA_URL = url;
try {
// eslint-disable-next-line no-undef
const json = await fetch(url, {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
}).then(res => res.json());
const insomniaConfig = new CuteConfig(json).generate();
return new App({
target: root,
props: {
config: insomniaConfig
}
});
} catch (err) {
console.error(err);
return new ErrorPage({
target: root
});
}
}
export default app();