2016-02-09 04:57:08 +00:00
|
|
|
import Vue from 'vue';
|
2015-12-29 01:35:22 +00:00
|
|
|
import ls from './services/ls';
|
2016-03-11 10:49:54 +00:00
|
|
|
import NProgress from 'nprogress';
|
2015-12-29 01:35:22 +00:00
|
|
|
|
2016-03-16 03:51:07 +00:00
|
|
|
let app = new Vue(require('./app.vue'));
|
2015-12-30 04:14:47 +00:00
|
|
|
|
2015-12-29 01:35:22 +00:00
|
|
|
Vue.config.debug = false;
|
2015-12-13 04:42:28 +00:00
|
|
|
Vue.use(require('vue-resource'));
|
|
|
|
Vue.http.options.root = '/api';
|
2015-12-29 01:35:22 +00:00
|
|
|
Vue.http.interceptors.push({
|
2016-01-01 06:16:17 +00:00
|
|
|
request(r) {
|
2016-03-16 03:51:07 +00:00
|
|
|
let token = ls.get('jwt-token');
|
2015-12-29 01:35:22 +00:00
|
|
|
|
|
|
|
if (token) {
|
2015-12-30 04:14:47 +00:00
|
|
|
Vue.http.headers.common.Authorization = `Bearer ${token}`;
|
2015-12-29 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 06:16:17 +00:00
|
|
|
return r;
|
2015-12-29 01:35:22 +00:00
|
|
|
},
|
|
|
|
|
2016-01-01 06:16:17 +00:00
|
|
|
response(r) {
|
2016-03-11 10:49:54 +00:00
|
|
|
NProgress.done();
|
|
|
|
|
2016-01-01 06:16:17 +00:00
|
|
|
if (r.status === 400 || r.status === 401) {
|
|
|
|
if (r.request.method !== 'POST' && r.request.url !== 'me') {
|
|
|
|
// This is not a failed login. Log out then.
|
|
|
|
app.logout();
|
|
|
|
}
|
2015-12-29 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 06:16:17 +00:00
|
|
|
if (r.headers && r.headers.Authorization) {
|
|
|
|
ls.set('jwt-token', r.headers.Authorization);
|
2015-12-29 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 06:16:17 +00:00
|
|
|
if (r.data && r.data.token && r.data.token.length > 10) {
|
|
|
|
ls.set('jwt-token', r.data.token);
|
2015-12-29 01:35:22 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 06:16:17 +00:00
|
|
|
return r;
|
2015-12-29 01:35:22 +00:00
|
|
|
},
|
|
|
|
});
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2016-01-26 06:24:23 +00:00
|
|
|
/**
|
|
|
|
* Thor! Odin's son, protector of Mankind
|
|
|
|
* Ride to meet your fate, your destiny awaits
|
|
|
|
* Thor! Hlödyn's son, protector of Mankind
|
|
|
|
* Ride to meet your fate, Ragnarök awaits
|
|
|
|
*/
|
2015-12-30 04:14:47 +00:00
|
|
|
app.$mount('body');
|