|
@@ -2,69 +2,10 @@ import axios from 'axios';
|
|
|
|
|
|
|
|
import { kuky_Authorization } from './storage';
|
|
import { kuky_Authorization } from './storage';
|
|
|
|
|
|
|
|
-import { getConfigField } from '../config/index';
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * 处理请求路径
|
|
|
|
|
- * 当在开发模式下,使用 vite 中配置 proxy,代理所有的 /api/ 相关的请求
|
|
|
|
|
- * 开发模式下使用外网地址:http://smartai.com:8191
|
|
|
|
|
- * 使用外网地址的原因是:有其他成员在非内网环境下进行共同开发,故无法使用内网地址
|
|
|
|
|
- *
|
|
|
|
|
- * 当在production模式下,通过此处的方法,将所有 /api/ 请求地址,调整为正常的地址
|
|
|
|
|
- * @param {object} config
|
|
|
|
|
- * @returns
|
|
|
|
|
- */
|
|
|
|
|
-function applyRequestProxyUrl(config) {
|
|
|
|
|
- /**
|
|
|
|
|
- * 如果是发布模式
|
|
|
|
|
- * 则不能使用代理的方式,需要直接请求服务器路径
|
|
|
|
|
- * API_BASE_URL 需要在 /public/config.js 中进行配置
|
|
|
|
|
- */
|
|
|
|
|
- if (import.meta.env.MODE === 'production') {
|
|
|
|
|
- const cur_url = config.url;
|
|
|
|
|
-
|
|
|
|
|
- const is_api_request = cur_url.indexOf('/api/') === 0;
|
|
|
|
|
-
|
|
|
|
|
- if (is_api_request) {
|
|
|
|
|
- const base_url = getConfigField('API_BASE_URL');
|
|
|
|
|
-
|
|
|
|
|
- if (!base_url) {
|
|
|
|
|
- throw new Error('关键配置项 API_BASE_URL 不存在,请在 /config.js 进行配置');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // const replace_str = base_url + '/';
|
|
|
|
|
-
|
|
|
|
|
- // const real_url = cur_url.replace('/api/', replace_str);
|
|
|
|
|
-
|
|
|
|
|
- config.url = base_url + cur_url;
|
|
|
|
|
- }
|
|
|
|
|
- if (cur_url.startsWith('/rgflow/')) {
|
|
|
|
|
- const base_url = getConfigField('RGFLOW_BASE_URL');
|
|
|
|
|
- if (!base_url) {
|
|
|
|
|
- throw new Error('关键配置项 RGFLOW_BASE_URL 不存在,请在 /config.js 进行配置');
|
|
|
|
|
- }
|
|
|
|
|
- const replace_str = base_url + '/';
|
|
|
|
|
- const real_url = cur_url.replace('/rgflow/', replace_str);
|
|
|
|
|
- config.url = real_url;
|
|
|
|
|
- }
|
|
|
|
|
- if (cur_url.startsWith('/dify/')) {
|
|
|
|
|
- const base_url = getConfigField('DIFY_BASE_URL');
|
|
|
|
|
- if (!base_url) {
|
|
|
|
|
- throw new Error('关键配置项 MITY_BASE_URL 不存在,请在 /config.js 进行配置');
|
|
|
|
|
- }
|
|
|
|
|
- const replace_str = base_url + '/';
|
|
|
|
|
- const real_url = cur_url.replace('/dify/', replace_str);
|
|
|
|
|
- config.url = real_url;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- // 开发环境,无需处理
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return config;
|
|
|
|
|
-}
|
|
|
|
|
|
|
+import replaceProxyUrl from './ajax/replace-proxy-url';
|
|
|
|
|
|
|
|
const ajax = axios.create({
|
|
const ajax = axios.create({
|
|
|
- // withCredentials: true, // 跨域发送 cookie
|
|
|
|
|
|
|
+ withCredentials: true, // 跨域发送 cookie
|
|
|
timeout: 300000, // 请求超时
|
|
timeout: 300000, // 请求超时
|
|
|
headers: {
|
|
headers: {
|
|
|
'Content-Type': 'application/json'
|
|
'Content-Type': 'application/json'
|
|
@@ -73,8 +14,7 @@ const ajax = axios.create({
|
|
|
|
|
|
|
|
ajax.interceptors.request.use(
|
|
ajax.interceptors.request.use(
|
|
|
(config) => {
|
|
(config) => {
|
|
|
- console.log('请求地址:', config.url);
|
|
|
|
|
- applyRequestProxyUrl(config);
|
|
|
|
|
|
|
+ replaceProxyUrl(config);
|
|
|
|
|
|
|
|
const token = kuky_Authorization.get();
|
|
const token = kuky_Authorization.get();
|
|
|
if (token) {
|
|
if (token) {
|