From b3074ce7654510d46197fe7897b89dfffea35c51 Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Fri, 7 Jul 2017 23:06:05 +0200 Subject: [PATCH 1/3] Remove config.js in favor of .env --- .env | 3 +++ src/App.js | 4 +++- src/apollo/client.js | 5 +++-- src/config.js | 25 ------------------------- src/index.js | 3 +-- 5 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 src/config.js diff --git a/.env b/.env index df09d75b..983f8528 100644 --- a/.env +++ b/.env @@ -1 +1,4 @@ PORT=3001 + +REACT_APP_BACKEND_HOST="http://localhost:3000" +REACT_APP_BACKEND_VERSION="> 0.0.0-90" diff --git a/src/App.js b/src/App.js index c9eba130..caf6feed 100644 --- a/src/App.js +++ b/src/App.js @@ -8,6 +8,8 @@ import styled from 'styled-components' import routes from './routes' import ReactCSSTransitionReplace from 'react-css-transition-replace' +const backendVersion = process.env.REACT_APP_BACKEND_VERSION + const App = (props) =>
@@ -42,7 +44,7 @@ const App = (props) => /> )} - +
const StyledApp = styled(App)` diff --git a/src/apollo/client.js b/src/apollo/client.js index f5a02c3a..c8e944f1 100644 --- a/src/apollo/client.js +++ b/src/apollo/client.js @@ -1,8 +1,9 @@ import { ApolloClient, createNetworkInterface } from 'react-apollo' -import config from '../config' + +const backendHost = process.env.REACT_APP_BACKEND_HOST const networkInterface = createNetworkInterface({ - uri: `${config.api.endpoint}/graphql` + uri: `${backendHost}/graphql` }) networkInterface.use([ { diff --git a/src/config.js b/src/config.js deleted file mode 100644 index e064ffab..00000000 --- a/src/config.js +++ /dev/null @@ -1,25 +0,0 @@ -let config = { - version: '> 0.0.0-90', - api: { - endpoint: 'http://localhost:3000' - } - }, - development = {}, - production = {}, - test = {} - -/* istanbul ignore next */ -switch (process.env.NODE_ENV) { -case 'development': - Object.assign(config, development) - break -case 'production': - Object.assign(config, production) - break -case 'test': - Object.assign(config, test) - break -default: -} - -export default config diff --git a/src/index.js b/src/index.js index a3dabfbb..8bbd038d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,6 @@ import React from 'react' import ReactDOM from 'react-dom' import registerServiceWorker from './registerServiceWorker' -import config from './config' import App from './App' import { BrowserRouter as Router } from 'react-router-dom' import { ApolloProvider } from 'react-apollo' @@ -14,7 +13,7 @@ ReactDOM.render( - + , From 288a11e623515ae1459dd9cc26e6d74d3517171a Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 10 Jul 2017 11:30:22 +0200 Subject: [PATCH 2/3] Put backend version option in package.json --- .env | 1 - package.json | 3 +++ src/App.js | 3 ++- src/config.json | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) create mode 120000 src/config.json diff --git a/.env b/.env index 983f8528..8fbd9883 100644 --- a/.env +++ b/.env @@ -1,4 +1,3 @@ PORT=3001 REACT_APP_BACKEND_HOST="http://localhost:3000" -REACT_APP_BACKEND_VERSION="> 0.0.0-90" diff --git a/package.json b/package.json index 46ec7cbf..459452f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,9 @@ { "name": "ontohub-frontend", "version": "0.1.0", + "ontohub": { + "backendVersion": "> 0.0.0-90" + }, "private": true, "license": "AGPL-3.0", "dependencies": { diff --git a/src/App.js b/src/App.js index caf6feed..a42379c9 100644 --- a/src/App.js +++ b/src/App.js @@ -7,8 +7,9 @@ import { Switch, Route } from 'react-router-dom' import styled from 'styled-components' import routes from './routes' import ReactCSSTransitionReplace from 'react-css-transition-replace' +import config from './config.json' -const backendVersion = process.env.REACT_APP_BACKEND_VERSION +const backendVersion = config.ontohub.backendVersion const App = (props) =>
diff --git a/src/config.json b/src/config.json new file mode 120000 index 00000000..4e26811d --- /dev/null +++ b/src/config.json @@ -0,0 +1 @@ +../package.json \ No newline at end of file From 3861f29773484ee2deb133d686d666aa4216139c Mon Sep 17 00:00:00 2001 From: Tom Gehrke Date: Mon, 10 Jul 2017 11:41:11 +0200 Subject: [PATCH 3/3] Add accept json header to requests --- src/apollo/client.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/apollo/client.js b/src/apollo/client.js index c8e944f1..eb61f305 100644 --- a/src/apollo/client.js +++ b/src/apollo/client.js @@ -9,11 +9,26 @@ networkInterface.use([ { applyMiddleware(req, next) { if (!req.options.headers) { - req.options.headers = {} // Create the header object if needed. + req.options.headers = {} } + next() + } + }, + { + applyMiddleware(req, next) { + Object.assign(req.options.headers, { + Accept: 'application/json' + }) + next() + } + }, + { + applyMiddleware(req, next) { let authToken = localStorage.getItem('auth-token') if (authToken) { - req.options.headers['Authorization'] = `Bearer ${authToken}` + Object.assign(req.options.headers, { + Authorization: `Bearer ${authToken}` + }) } next() }