1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import axios, { type AxiosInstance } from 'axios' import { MainHost } from './constants' export class BaseRequest { private axiosInst: AxiosInstance constructor(host: string) { this.axiosInst = axios.create({ baseURL: host, withCredentials: true, headers: { 'Content-Type': 'application/json', }, timeout: 15000, }) } sendRequest(method: string, path: string, params: any = null, data: any = null): Promise<any> { return new Promise((resolve, reject) => { this.axiosInst .request({ method, url: path, params, data }) .then((res) => { resolve(res.data) }) .catch(reject) }) } } export const mainRequest = new BaseRequest(MainHost)
|