2020-09-04 23:50:05 +08:00
|
|
|
/**
|
|
|
|
* Before you edit these, read the documentation on how these files are compiled:
|
|
|
|
* https://docs.phpvms.net/customize/building-assets
|
|
|
|
*
|
|
|
|
* Edits here don't take place until you compile these assets and then upload them.
|
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
|
|
|
|
import config from './config';
|
|
|
|
|
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run an API request, with some common options
|
|
|
|
*
|
|
|
|
* @param {Object|String} _opts Axios request options, or pass a URL
|
|
|
|
* @param {String} _opts.url
|
|
|
|
*/
|
|
|
|
export default async (_opts) => {
|
|
|
|
if (typeof _opts === 'string' || _opts instanceof String) {
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
_opts = {
|
|
|
|
url: _opts,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const opts = Object.assign({}, {
|
|
|
|
baseURL: config.base_url,
|
|
|
|
headers: {
|
|
|
|
'X-API-KEY': config.api_key,
|
|
|
|
'X-CSRF-TOKEN': config.csrf_token,
|
|
|
|
},
|
|
|
|
}, _opts);
|
|
|
|
|
2020-03-03 23:20:13 +08:00
|
|
|
console.log(opts);
|
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
return axios.request(opts);
|
|
|
|
};
|