add config.json to configure api URL

Load config.json at startup

Change-Id: I38df3611daed155c91fccdaf175df4b9778953ae
This commit is contained in:
Guillaume Vincent 2018-12-20 17:46:12 +01:00
parent d42b04f049
commit df050a5b51
3 changed files with 16 additions and 7 deletions

3
public/config.json Normal file
View File

@ -0,0 +1,3 @@
{
"apiURL": "http://localhost:8000"
}

View File

@ -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() {

View File

@ -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;
});
};
}