| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- const axios = require('axios')
- const { pyapp } = require('../config/app.config.json')
- /* 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
- }
|