Skip to content

Commit 935749e

Browse files
authored
Merge pull request #107 from xsnippet/runtime-conf
Probe runtime config before passing control to app
2 parents 47b7158 + a91bb80 commit 935749e

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

src/components/App.jsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,42 @@ import React from 'react'
33
import Header from './Header'
44
import Main from './Main'
55
import Sidebar from './Sidebar'
6+
import Spinner from './common/Spinner'
7+
import conf from '../conf'
68

79
import '../styles/App.styl'
810

9-
const App = () => (
10-
[
11-
<Header key="header" />,
12-
<div className="content" key="content">
13-
<Sidebar />
14-
<Main />
15-
</div>,
16-
]
17-
)
11+
class App extends React.Component {
12+
constructor(props) {
13+
super(props)
14+
this.state = {
15+
isLoading: true,
16+
}
17+
18+
fetch(process.env.RUNTIME_CONF_URI)
19+
.then((response) => {
20+
if (response.status === 404) {
21+
return {}
22+
}
23+
return response.json()
24+
})
25+
.then(json => Object.assign(conf, json))
26+
.then(() => this.setState({ isLoading: false }))
27+
}
28+
29+
render() {
30+
if (this.state.isLoading) {
31+
return <Spinner />
32+
}
33+
34+
return [
35+
<Header key="header" />,
36+
<div className="content" key="content">
37+
<Sidebar />
38+
<Main />
39+
</div>,
40+
]
41+
}
42+
}
1843

1944
export default App

webpack.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ module.exports = () => {
109109
'xml',
110110
'yaml',
111111
'django']
112+
const assetsPath = process.env.ASSETS_PATH == null
113+
? '/'
114+
: process.env.ASSETS_PATH
112115

113116
const conf = {
114117
// Assume we are targeting production environments by default; the value
@@ -145,7 +148,7 @@ module.exports = () => {
145148
output: {
146149
filename: '[name].[chunkhash].js',
147150
path: path.resolve(__dirname, 'dist'),
148-
publicPath: process.env.ASSET_PATH || '/',
151+
publicPath: assetsPath,
149152
},
150153

151154
module: {
@@ -219,6 +222,7 @@ module.exports = () => {
219222
new webpack.EnvironmentPlugin({
220223
API_BASE_URI: null,
221224
RAW_SNIPPET_URI_FORMAT: null,
225+
RUNTIME_CONF_URI: `${assetsPath}conf.json`,
222226
}),
223227

224228
// Similar to JavaScript, we use [chunkhash] in order to invalidate

0 commit comments

Comments
 (0)