| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- const axios = require('axios')
- const { readConfigFile } = require('../utils/config');
- const pyapp = readConfigFile().pyapp
- /* axios.defaults.withCredentials = true*/
- // create an axios instance
- const service = axios.create()
- const baseUrl = 'http://'+pyapp+':7074'
- const basePrefixUrl = 'api'
- const timeout = 600000
- const uploadTimeout = 600000
- function request(config) {
- return service(config)
- }
- /* get 默认取数据 */
- function get(config) {
- return _get({ ...config, baseUrl })
- }
- function getPay(config) {
- return _get({ ...config, basePayUrl })
- }
- function _get(config = {
- baseUrl,
- url: '',
- data: {}
- }) {
- const thisBasePrefixUrl = config.basePrefixUrl !== undefined ? config.basePrefixUrl : basePrefixUrl
- return service.get(config.baseUrl + config.url, {
- params: {
- ...config.data
- },
- headers: config.headers || {},
- timeout: config.timeout || timeout
- })
- }
- function post(config) {
- return _post({ ...config, baseUrl })
- }
- function postPay(config) {
- return _post({ ...config, baseUrl: basePayUrl })
- }
- /* post 默认提交数据 */
- function _post(config = {
- baseUrl,
- url: '',
- data: {}
- }) {
- const thisBasePrefixUrl = config.basePrefixUrl !== undefined ? config.basePrefixUrl : basePrefixUrl
- return service.post(config.baseUrl + config.url, {
- ...config.data
- }, {
- headers: config.headers || {},
- timeout: config.timeout || timeout,
- roles:config.roles,
- })
- }
- module.exports = {
- get,
- post
- }
|