修改 nacos-federation 插件,实现 接口请求基地址从 配置中心获取,并注入到环境变量中
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
export class HttpConfig {
|
||||
public static DevBaseUrl: string = "http://127.0.0.1:3210/api"
|
||||
public static prodBaseUrl: string = "http://127.0.0.1:3210/api/"
|
||||
// public static DevBaseUrl: string = "http://127.0.0.1:3210/api"
|
||||
public static DevBaseUrl: string = import.meta.env.VITE_DEVBASEURL
|
||||
|
||||
// public static ProdBaseUrl: string = "http://127.0.0.1:3210/api/"
|
||||
public static ProdBaseUrl: string = import.meta.env.VITE_PRODBASEURL
|
||||
|
||||
public static apiList: string = ""
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios, {AxiosError, type AxiosInstance, type AxiosRequestConfig} from "axios";
|
||||
import {UrlCheckUtils} from '../utils/index'
|
||||
import axios, { AxiosError, type AxiosInstance, type AxiosRequestConfig } from "axios";
|
||||
import { UrlCheckUtils } from '../utils/index'
|
||||
|
||||
|
||||
class AxiosInfra {
|
||||
@@ -32,7 +32,7 @@ class AxiosInfra {
|
||||
|
||||
/**
|
||||
* Put 请求
|
||||
* 请求参数请参考接口:RequestParams
|
||||
* 请求参数请参考接口:RequestParams
|
||||
* @param params
|
||||
*/
|
||||
public async put(params: AxiosRequestConfig): Promise<any> {
|
||||
@@ -41,7 +41,7 @@ class AxiosInfra {
|
||||
|
||||
/**
|
||||
* delete 请求
|
||||
* 请求参数请参考接口:RequestParams
|
||||
* 请求参数请参考接口:RequestParams
|
||||
* @param params
|
||||
*/
|
||||
public async delete(params: AxiosRequestConfig): Promise<any> {
|
||||
@@ -60,16 +60,16 @@ class AxiosInfra {
|
||||
(error: AxiosError) => {
|
||||
console.log(`
|
||||
❌ 请求错误 ❌
|
||||
1、基地址: ${error.config?.baseURL}
|
||||
2、短地址: ${error.config?.url}
|
||||
3、请求 方式: ${error.config?.method}
|
||||
4、请求 参数: ${JSON.stringify(error.config?.params)}
|
||||
5、请求 头 : ${JSON.stringify(error.config?.headers)}
|
||||
1、基地址: ${ error.config?.baseURL }
|
||||
2、短地址: ${ error.config?.url }
|
||||
3、请求 方式: ${ error.config?.method }
|
||||
4、请求 参数: ${ JSON.stringify(error.config?.params) }
|
||||
5、请求 头 : ${ JSON.stringify(error.config?.headers) }
|
||||
|
||||
------------------------------------------------------------
|
||||
|
||||
6、错误信息为: ${error.message}
|
||||
7、错误代码为: ${error.stack}
|
||||
6、错误信息为: ${ error.message }
|
||||
7、错误代码为: ${ error.stack }
|
||||
`);
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {HttpConfig} from '../config'
|
||||
import { HttpConfig } from '../config'
|
||||
|
||||
export class UrlCheckUtils {
|
||||
|
||||
public static check() {
|
||||
if (import.meta.env.MODE === 'production') {
|
||||
return HttpConfig.prodBaseUrl;
|
||||
return HttpConfig.ProdBaseUrl;
|
||||
} else {
|
||||
return HttpConfig.DevBaseUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user