koel/resources/assets/js/main.js

56 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-02-09 04:57:08 +00:00
import Vue from 'vue';
2016-03-11 10:49:54 +00:00
import NProgress from 'nprogress';
2016-06-25 10:15:57 +00:00
import { ls } from './services';
2016-06-25 05:24:55 +00:00
import { event } from './utils';
2015-12-30 04:14:47 +00:00
2016-06-25 10:15:57 +00:00
import App from './app.vue'
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-06-25 16:05:24 +00:00
request(r) {
const token = ls.get('jwt-token');
2015-12-29 01:35:22 +00:00
2016-06-25 16:05:24 +00:00
if (token) {
Vue.http.headers.common.Authorization = `Bearer ${token}`;
}
2015-12-29 01:35:22 +00:00
2016-06-25 16:05:24 +00:00
return r;
},
2015-12-29 01:35:22 +00:00
2016-06-25 16:05:24 +00:00
response(r) {
NProgress.done();
2016-03-11 10:49:54 +00:00
2016-06-25 16:05:24 +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.
event.emit('logout');
}
}
2015-12-29 01:35:22 +00:00
2016-06-25 16:05:24 +00:00
if (r.headers && r.headers.Authorization) {
ls.set('jwt-token', r.headers.Authorization);
}
2015-12-29 01:35:22 +00:00
2016-06-25 16:05:24 +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-06-25 16:05:24 +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
/**
2016-07-08 04:46:15 +00:00
* For Ancelot, the ancient cross of war
* for the holy town of Gods
* Gloria, gloria perpetua
* in this dawn of victory
2016-01-26 06:24:23 +00:00
*/
2016-06-25 05:24:55 +00:00
new Vue({
2016-06-25 16:05:24 +00:00
el: '#app',
render: h => h(App),
created() { event.init() },
2016-06-25 05:24:55 +00:00
});