2018-03-13 06:30:52 +08:00
|
|
|
/**
|
|
|
|
* Bootstrap any Javascript libraries required
|
|
|
|
*/
|
|
|
|
|
2019-08-28 03:08:42 +08:00
|
|
|
|
2018-03-28 07:18:25 +08:00
|
|
|
window.axios = require('axios');
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2019-08-28 03:08:42 +08:00
|
|
|
import Storage from "./storage";
|
|
|
|
|
2018-03-13 09:14:55 +08:00
|
|
|
/**
|
|
|
|
* Container for phpVMS specific functions
|
|
|
|
*/
|
2019-08-28 03:08:42 +08:00
|
|
|
window.phpvms = {
|
|
|
|
config: {},
|
|
|
|
Storage,
|
|
|
|
};
|
2018-03-13 06:30:52 +08:00
|
|
|
|
|
|
|
/**
|
2018-03-13 09:14:55 +08:00
|
|
|
* Configure Axios with both the csrf token and the API key
|
2018-03-13 06:30:52 +08:00
|
|
|
*/
|
2018-03-29 12:04:53 +08:00
|
|
|
|
|
|
|
const base_url = document.head.querySelector('meta[name="base-url"]');
|
|
|
|
if(base_url) {
|
2019-08-28 03:08:42 +08:00
|
|
|
console.log(`baseURL=${base_url.content}`);
|
|
|
|
window.phpvms.config.base_url = base_url.content;
|
|
|
|
window.axios.default.baseURL = base_url.content;
|
2018-03-29 12:04:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-28 07:18:25 +08:00
|
|
|
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
|
|
|
const token = document.head.querySelector('meta[name="csrf-token"]');
|
2018-03-13 06:30:52 +08:00
|
|
|
|
|
|
|
if (token) {
|
2019-08-28 03:08:42 +08:00
|
|
|
window.phpvms.config.csrf_token = token.content;
|
2018-03-14 22:07:41 +08:00
|
|
|
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content
|
2018-03-13 06:30:52 +08:00
|
|
|
} else {
|
2018-03-14 22:07:41 +08:00
|
|
|
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token')
|
2018-03-13 06:30:52 +08:00
|
|
|
}
|
2018-03-13 09:14:55 +08:00
|
|
|
|
2018-03-28 07:18:25 +08:00
|
|
|
const api_key = document.head.querySelector('meta[name="api-key"]');
|
2018-03-14 22:07:41 +08:00
|
|
|
if (api_key) {
|
2018-03-28 07:18:25 +08:00
|
|
|
window.axios.defaults.headers.common['x-api-key'] = api_key.content;
|
2019-08-28 03:08:42 +08:00
|
|
|
window.phpvms.config.user_api_key = api_key.content;
|
2018-03-14 22:07:41 +08:00
|
|
|
window.PHPVMS_USER_API_KEY = api_key.content
|
2018-03-13 09:14:55 +08:00
|
|
|
} else {
|
2019-08-28 03:08:42 +08:00
|
|
|
window.phpvms.config.user_api_key = false;
|
2018-03-28 07:18:25 +08:00
|
|
|
window.PHPVMS_USER_API_KEY = false;
|
2018-03-14 22:07:41 +08:00
|
|
|
console.error('API Key not found!')
|
2018-03-13 09:14:55 +08:00
|
|
|
}
|
2018-05-04 04:07:16 +08:00
|
|
|
|
|
|
|
require('./common');
|