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 <me@sudhanshug.com>
This commit is contained in:
Sudhanshu Gautam 2019-10-06 23:54:13 +05:30
parent 8988781d26
commit b21e082518
3 changed files with 13 additions and 11 deletions

View file

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

View file

@ -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 {
</ExpansionPanelDetails>
</ExpansionPanel>
</Grid>
<Grid item xs>
<Grid item xs className="downloads">
<b>{this.props.t('Downloads')}: </b>
{this.state.builtImages.map(image => (
<div key={image.url}>

View file

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