phpvms/resources/js/bootstrap.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

/**
* Bootstrap any Javascript libraries required
*/
window.axios = require('axios');
import Storage from "./storage";
/**
* Container for phpVMS specific functions
*/
window.phpvms = {
config: {},
Storage,
};
/**
* Configure Axios with both the csrf token and the API key
*/
2018-03-29 12:04:53 +08:00
const base_url = document.head.querySelector('meta[name="base-url"]');
if(base_url) {
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
}
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
const token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
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
} else {
2018-03-14 22:07:41 +08:00
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token')
}
const api_key = document.head.querySelector('meta[name="api-key"]');
2018-03-14 22:07:41 +08:00
if (api_key) {
window.axios.defaults.headers.common['x-api-key'] = api_key.content;
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
} else {
window.phpvms.config.user_api_key = false;
window.PHPVMS_USER_API_KEY = false;
2018-03-14 22:07:41 +08:00
console.error('API Key not found!')
}
require('./common');