FUNKING CONFIG
This commit is contained in:
parent
7273f61580
commit
6a33ad90b5
5 changed files with 67 additions and 6 deletions
3
public/config.json
Normal file
3
public/config.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"VIKUNJA_API_BASE_URL": "http://localhost:8080/api/v1/"
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"API_URL": "http://localhost:8080/api/v1/"
|
||||
}
|
1
src/.env
1
src/.env
|
@ -1 +0,0 @@
|
|||
VIKUNJA_ROOT_API_URL=http://localhost:8080/api/v1/
|
47
src/config/index.js
Normal file
47
src/config/index.js
Normal 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/'
|
||||
}
|
|
@ -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
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue