forked from DependencyTrack/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
99 lines (92 loc) · 2.99 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import Vue from 'vue';
import BootstrapVue from 'bootstrap-vue';
import App from './App';
import router from './router';
import i18n from './i18n';
import './validation';
import './plugins/table.js';
import axios from 'axios';
import VueAxios from 'vue-axios';
import vueDebounce from 'vue-debounce';
import VuePageTitle from 'vue-page-title';
import '@/directives/VuePermission';
import VueToastr from 'vue-toastr';
import api from './shared/api.json';
import oidc from './shared/oidc.json';
import version from './version';
import { getContextPath } from './shared/utils';
Vue.use(BootstrapVue);
Vue.use(VueAxios, axios);
Vue.use(VueToastr, {
defaultTimeout: 5000,
defaultProgressBar: false,
defaultProgressBarValue: 0,
defaultPosition: 'toast-top-right',
defaultCloseOnHover: false,
});
Vue.use(vueDebounce, { defaultTime: '750ms' });
Vue.use(VuePageTitle, { prefix: 'Dependency-Track -', router });
Vue.prototype.$api = api;
Vue.prototype.$oidc = oidc;
const contextPath = getContextPath();
axios
.get(contextPath + '/static/config.json')
.then((response) => {
if (response.data.API_BASE_URL && response.data.API_BASE_URL !== '') {
Vue.prototype.$api.BASE_URL = response.data.API_BASE_URL;
} else {
Vue.prototype.$api.BASE_URL = contextPath;
}
// Send XHR cross-site cookie credentials
Vue.prototype.$api.WITH_CREDENTIALS =
response.data.API_WITH_CREDENTIALS &&
response.data.API_WITH_CREDENTIALS.toLowerCase() === 'true';
// OpenID Connect
Vue.prototype.$oidc.ISSUER = response.data.OIDC_ISSUER;
Vue.prototype.$oidc.CLIENT_ID = response.data.OIDC_CLIENT_ID;
Vue.prototype.$oidc.SCOPE = response.data.OIDC_SCOPE;
Vue.prototype.$oidc.FLOW = response.data.OIDC_FLOW;
if (response.data.OIDC_LOGIN_BUTTON_TEXT) {
Vue.prototype.$oidc.LOGIN_BUTTON_TEXT =
response.data.OIDC_LOGIN_BUTTON_TEXT;
} else {
Vue.prototype.$oidc.LOGIN_BUTTON_TEXT = '';
}
createVueApp();
})
.catch(function (error) {
console.log(
'Cannot retrieve static/config.json from host. This is expected behavior in development environments.',
);
createVueApp();
});
/**
* Removed finally block due to:
* https://github.com/DependencyTrack/frontend/issues/34
*/
function createVueApp() {
/*
Register global $dtrack variable which will be the response body from /api/version.
$dtrack can then be used anywhere in the app to get information about the server,
the version of dtrack, timestamp, uuid, Alpine version, etc.
*/
axios
.get(`${Vue.prototype.$api.BASE_URL}/${Vue.prototype.$api.URL_ABOUT}`)
.then((result) => {
Vue.prototype.$dtrack = result.data;
});
Vue.prototype.$version = version;
new Vue({
el: '#app',
router,
template: '<App/>',
components: {
App,
},
i18n,
});
}