discord-client/webpack/setup.js

55 lines
1.3 KiB
JavaScript
Raw Normal View History

/* (1) VueJS data */
import VueRouter from 'vue-router'
import GlobalStore from './lib/gstore'
import routes from './routes'
/* (2) Custom libs */
import Authentication from './lib/authentication.js'
import XHRClientDriver from './lib/client/xhr.js'
import WebSocketClientDriver from './lib/client/ws.js'
/* (1) Custom lib accessors
---------------------------------------------------------*/
2018-03-25 11:59:43 +00:00
/* (1) Global Store for Vue */
window.gs = new GlobalStore();
2018-03-25 11:59:43 +00:00
/* (2) Authentication token management */
window.auth = new Authentication();
/* (3) XHR / WebSocket drivers */
window.xhrcd = XHRClientDriver;
window.wscd = WebSocketClientDriver;
/* (4) ClientDriver instances */
window.api = new XHRClientDriver('api.douscord.xdrm.io');
window.ws = new WebSocketClientDriver('ws.douscord.xdrm.io');
/* (2) Global data
---------------------------------------------------------*/
/* (1) Get Full URI */
gs.set('URI', document.URL.replace(/^(?:[^\/]+\/\/|[^\/]+\/)/, '').split('/').filter(function(v,i){ return !!i && v.length; }));
/* (2) Store routes */
gs.set('routes', routes);
/* (3) Store if authenticated */
gs.set('auth', auth.token !== null);
/* (4) Init. vue router */
gs.set('router', new VueRouter({
routes: gs.get.auth ? gs.get.routes['auth'] : gs.get.routes['noauth']
}));