From df050a5b51223cace9899d3d4e78af6657d93502 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 20 Dec 2018 17:46:12 +0100 Subject: [PATCH] add config.json to configure api URL Load config.json at startup Change-Id: I38df3611daed155c91fccdaf175df4b9778953ae --- public/config.json | 3 +++ src/App.js | 9 ++------- src/config/configActions.js | 11 +++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 public/config.json diff --git a/public/config.json b/public/config.json new file mode 100644 index 0000000..06cfeb2 --- /dev/null +++ b/public/config.json @@ -0,0 +1,3 @@ +{ + "apiURL": "http://localhost:8000" +} diff --git a/src/App.js b/src/App.js index fb70c40..493ceca 100644 --- a/src/App.js +++ b/src/App.js @@ -4,7 +4,7 @@ import { Provider } from "react-redux"; import "@patternfly/patternfly-next/patternfly.css"; import store from "./store"; -import { setConfig } from "./config/configActions"; +import { getConfig } from "./config/configActions"; import * as Containers from "./containers"; class App extends Component { @@ -13,12 +13,7 @@ class App extends Component { }; componentDidMount() { - store.dispatch( - setConfig({ - apiURL: "http://localhost:8000" - }) - ); - this.setState({ isLoading: false }); + store.dispatch(getConfig()).then(() => this.setState({ isLoading: false })); } render() { diff --git a/src/config/configActions.js b/src/config/configActions.js index cc7958e..455e9d2 100644 --- a/src/config/configActions.js +++ b/src/config/configActions.js @@ -1,3 +1,4 @@ +import axios from "axios"; import * as types from "./configActionsTypes"; export function setConfig(config) { @@ -6,3 +7,13 @@ export function setConfig(config) { config }; } + +export function getConfig() { + return dispatch => { + return axios.get("/config.json").then(response => { + const config = response.data; + dispatch(setConfig(config)); + return response; + }); + }; +}