This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
62 lines (56 loc) · 1.59 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Styles
import './styles/bootstrap/bootstrap.scss'
import './styles/main.scss'
import 'babel-polyfill'
import React from 'react'
import { render } from 'react-dom'
import Root from './containers/Root'
import configureStore from './store/configureStore'
// https://deisdash.some.deis.host.com:123 becomes
// https://deis.some.deis.host.com:123
const guessDefaultController = () => {
const host = window.location.host
const protocol = window.location.protocol
// e.g.: localhost
if (host.split('.').length === 1) {
return `${protocol}//deis.local3.deisapp.com`
}
const deisHost = ['deis'].concat(host.split('.').slice(1)).join('.')
return `${protocol}//${deisHost}`
}
const localStorage = window.localStorage
const defaultController = localStorage.controller
|| process.env.DEFAULT_CONTROLLER
|| guessDefaultController()
const controllerLocked = !!process.env.CONTROLLER_LOCKED
const getControllerInfo = () => {
try {
return JSON.parse(localStorage.controllerInfo)
} catch (err) {
console.log(err)
}
return null
}
const store = configureStore({
controller: localStorage.controller || defaultController,
controllerInfo: getControllerInfo(),
user: (() => {
if (localStorage.token && localStorage.username) {
return {
token: localStorage.token,
username: localStorage.username,
}
}
return null
})(),
version: process.env.VERSION,
ui: {
// TODO: (not implemented)
// Disable the controller input by default on the home page?
controllerLocked,
},
})
render(
<Root store={store} />,
document.getElementById('root')
)