FUNKING CONFIG

This commit is contained in:
konrad 2018-09-08 21:18:42 +02:00
parent 7273f61580
commit 6a33ad90b5
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
5 changed files with 67 additions and 6 deletions

3
public/config.json Normal file
View file

@ -0,0 +1,3 @@
{
"VIKUNJA_API_BASE_URL": "http://localhost:8080/api/v1/"
}

View file

@ -1,3 +0,0 @@
{
"API_URL": "http://localhost:8080/api/v1/"
}

View file

@ -1 +0,0 @@
VIKUNJA_ROOT_API_URL=http://localhost:8080/api/v1/

47
src/config/index.js Normal file
View file

@ -0,0 +1,47 @@
/* eslint-disable */
import axios from "axios";
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default {
initConfig() {
//this.config = {VIKUNJA_API_BASE_URL: '/api/v1/'}
axios.get('config.json')
.then(function (response) {
/*console.log('response', response.data);
console.log('self', self.config);
self.config = response.data*/
// eslint-disable-next-line
//console.log(response.data);
localStorage.removeItem('config')
localStorage.setItem('config', JSON.stringify(response.data))
})
.catch(function (error) {
// eslint-disable-next-line
console.log(error);
})
/*console.log('final', conf.data);
return conf.data*/
},
async configReady() {
while(!localStorage.getItem('config')){
await sleep(100);
}
return true
},
get() {
this.configReady()
return JSON.parse(localStorage.getItem('config'))
},
VIKUNJA_API_BASE_URL: '/api/v1/'
}

View file

@ -1,6 +1,21 @@
import axios from 'axios'
let config = require('../../siteconfig.json')
//let config = require('../../siteconfig.json')
//import config from '../config/dev.env'
//import Vue from 'vue'
import config from '../config'
config.initConfig()
let conf = config.get()
/*
conf.then(function (r) {
// eslint-disable-next-line
console.log(r)
})*/
config.configReady()
// eslint-disable-next-line
console.log(conf)
export const HTTP = axios.create({
baseURL: config.API_URL
baseURL: conf.VIKUNJA_API_BASE_URL
})