Skip to content

Commit e86072d

Browse files
authored
Remove config.js in favor of .env (#92)
* Remove config.js in favor of .env * Put backend version option in package.json * Add accept json header to requests
1 parent 4c5fda7 commit e86072d

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
PORT=3001
2+
3+
REACT_APP_BACKEND_HOST="http://localhost:3000"

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "ontohub-frontend",
33
"version": "0.1.0",
4+
"ontohub": {
5+
"backendVersion": "> 0.0.0-90"
6+
},
47
"private": true,
58
"license": "AGPL-3.0",
69
"dependencies": {

src/App.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { Switch, Route } from 'react-router-dom'
77
import styled from 'styled-components'
88
import routes from './routes'
99
import ReactCSSTransitionReplace from 'react-css-transition-replace'
10+
import config from './config.json'
11+
12+
const backendVersion = config.ontohub.backendVersion
1013

1114
const App = (props) =>
1215
<div className={props.className}>
@@ -42,7 +45,7 @@ const App = (props) =>
4245
/>
4346
)}
4447
</Switch>
45-
<VersionWarning requirement={props.config.version} />
48+
<VersionWarning requirement={backendVersion} />
4649
</div>
4750

4851
const StyledApp = styled(App)`

src/apollo/client.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
import { ApolloClient, createNetworkInterface } from 'react-apollo'
2-
import config from '../config'
2+
3+
const backendHost = process.env.REACT_APP_BACKEND_HOST
34

45
const networkInterface = createNetworkInterface({
5-
uri: `${config.api.endpoint}/graphql`
6+
uri: `${backendHost}/graphql`
67
})
78
networkInterface.use([
89
{
910
applyMiddleware(req, next) {
1011
if (!req.options.headers) {
11-
req.options.headers = {} // Create the header object if needed.
12+
req.options.headers = {}
1213
}
14+
next()
15+
}
16+
},
17+
{
18+
applyMiddleware(req, next) {
19+
Object.assign(req.options.headers, {
20+
Accept: 'application/json'
21+
})
22+
next()
23+
}
24+
},
25+
{
26+
applyMiddleware(req, next) {
1327
let authToken = localStorage.getItem('auth-token')
1428
if (authToken) {
15-
req.options.headers['Authorization'] = `Bearer ${authToken}`
29+
Object.assign(req.options.headers, {
30+
Authorization: `Bearer ${authToken}`
31+
})
1632
}
1733
next()
1834
}

src/config.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../package.json

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
33
import registerServiceWorker from './registerServiceWorker'
4-
import config from './config'
54
import App from './App'
65
import { BrowserRouter as Router } from 'react-router-dom'
76
import { ApolloProvider } from 'react-apollo'
@@ -14,7 +13,7 @@ ReactDOM.render(
1413
<ApolloProvider client={client}>
1514
<Router>
1615
<ThemeProvider theme={theme}>
17-
<App config={config} />
16+
<App />
1817
</ThemeProvider>
1918
</Router>
2019
</ApolloProvider>,

0 commit comments

Comments
 (0)