From b21e08251802a11b5d8ab96abe9dc4fb790cc307 Mon Sep 17 00:00:00 2001 From: Sudhanshu Gautam Date: Sun, 6 Oct 2019 23:54:13 +0530 Subject: [PATCH] Introduce config and fix minor issues Previously, basic config like URLs were hard-coded in the code itself. Now they reside in the `config.js` file. Also fixes #17 Signed-off-by: Sudhanshu Gautam --- src/config.js | 8 +++++++- src/containers/home/home.js | 8 +++----- src/services/data.js | 8 +++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/config.js b/src/config.js index 3a497d8..1e12cab 100644 --- a/src/config.js +++ b/src/config.js @@ -1,4 +1,10 @@ -const defaults = {}; +const asu_base = 'https://aparcar.stephen304.com'; +const defaults = { + CORSbyPass: 'https://cors-anywhere.herokuapp.com/', + base_api: asu_base + '/api/', + asu: asu_base, + asu_vanilla: asu_base + '/download/json-demo/openwrt/', +}; const prod = { i18nDebug: false, }; diff --git a/src/containers/home/home.js b/src/containers/home/home.js index a92bde8..f080d92 100644 --- a/src/containers/home/home.js +++ b/src/containers/home/home.js @@ -34,6 +34,7 @@ import './home.scss'; import { withTranslation } from 'react-i18next'; import FuzzySet from 'fuzzyset.js'; +import config from '../../config'; import DataService from '../../services/data'; import AlertDialog from '../../components/alert-dialog'; @@ -58,10 +59,7 @@ TabContainer.propTypes = { }; const sleep = m => new Promise(r => setTimeout(r, m)); -const CORSbyPass = 'https://cors-anywhere.herokuapp.com/'; -const asu = 'https://aparcar.stephen304.com'; -const asu_vanilla = - 'https://aparcar.stephen304.com/download/json-demo/openwrt/'; +const { CORSbyPass, asu, asu_vanilla } = config; class Home extends React.Component { state = { @@ -552,7 +550,7 @@ class Home extends React.Component { - + {this.props.t('Downloads')}: {this.state.builtImages.map(image => (
diff --git a/src/services/data.js b/src/services/data.js index 89fc9c8..8351164 100644 --- a/src/services/data.js +++ b/src/services/data.js @@ -1,7 +1,8 @@ import axios from 'axios'; +import config from '../config'; -const base_api = - 'https://cors-anywhere.herokuapp.com/https://aparcar.stephen304.com/api/'; +const { CORSbyPass, base_api: api } = config; +const base_api = CORSbyPass + api; class DataService { getVersions = versionsPath => axios.get(versionsPath); @@ -39,9 +40,6 @@ class DataService { buildStatusCheck = request_hash => axios.get(base_api + 'build-request/' + request_hash); - - getFiles = files_url => - axios.get('https://chef.libremesh.org' + files_url).then(res => res.data); } export default DataService;