From 6a33ad90b55ccac4d0c262a7830a6842d649b2ed Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 8 Sep 2018 21:18:42 +0200 Subject: [PATCH] FUNKING CONFIG --- public/config.json | 3 +++ siteconfig.json | 3 --- src/.env | 1 - src/config/index.js | 47 ++++++++++++++++++++++++++++++++++++++++ src/http-common/index.js | 19 ++++++++++++++-- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 public/config.json delete mode 100644 siteconfig.json delete mode 100644 src/.env create mode 100644 src/config/index.js diff --git a/public/config.json b/public/config.json new file mode 100644 index 00000000..a481f397 --- /dev/null +++ b/public/config.json @@ -0,0 +1,3 @@ +{ + "VIKUNJA_API_BASE_URL": "http://localhost:8080/api/v1/" +} diff --git a/siteconfig.json b/siteconfig.json deleted file mode 100644 index 57d746ed..00000000 --- a/siteconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "API_URL": "http://localhost:8080/api/v1/" -} diff --git a/src/.env b/src/.env deleted file mode 100644 index 20f4be4c..00000000 --- a/src/.env +++ /dev/null @@ -1 +0,0 @@ -VIKUNJA_ROOT_API_URL=http://localhost:8080/api/v1/ \ No newline at end of file diff --git a/src/config/index.js b/src/config/index.js new file mode 100644 index 00000000..20006400 --- /dev/null +++ b/src/config/index.js @@ -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/' +} \ No newline at end of file diff --git a/src/http-common/index.js b/src/http-common/index.js index 297ee29a..f97f0720 100644 --- a/src/http-common/index.js +++ b/src/http-common/index.js @@ -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 })