1- import { defineConfig } from "vite" ;
1+ import { defineConfig } from "vite" ;
22import react from "@vitejs/plugin-react" ;
33import tailwindcss from "@tailwindcss/vite" ;
44import path from "path" ; // 需要安装 Node.js 的类型声明(@types/node)
@@ -12,30 +12,55 @@ export default defineConfig({
1212 } ,
1313 } ,
1414 server : {
15- // headers: {
16- // "Access-Control-Allow-Origin": "*",
17- // "access-control-allow-headers":
18- // "Origin, X-Requested-With, Content-Type, Accept",
19- // },
20- proxy : {
21- "^/api" : {
22- target : "http://localhost:8080" , // 本地后端服务地址
15+ host : "0.0.0.0" ,
16+ proxy : ( ( ) => {
17+ const pythonProxyConfig = {
18+ target : "http://localhost:18000" ,
2319 changeOrigin : true ,
2420 secure : false ,
25- rewrite : ( path ) => path . replace ( / ^ \/ a p i / , "/api" ) ,
26- configure : ( proxy , options ) => {
27- // proxy 是 'http-proxy' 的实例
28- proxy . on ( "proxyReq" , ( proxyReq , req , res ) => {
29- // 可以在这里修改请求头
30- proxyReq . removeHeader ( "referer" ) ;
31- proxyReq . removeHeader ( "origin" ) ;
21+ configure : ( proxy : { on : ( event : string , handler : ( arg : unknown ) => void ) => void } ) => {
22+ proxy . on ( "proxyReq" , ( proxyReq : unknown ) => {
23+ ( proxyReq as { removeHeader : ( name : string ) => void } ) . removeHeader ( "referer" ) ;
24+ ( proxyReq as { removeHeader : ( name : string ) => void } ) . removeHeader ( "origin" ) ;
3225 } ) ;
33- proxy . on ( "proxyRes" , ( proxyRes , req , res ) => {
34- delete proxyRes . headers [ "set-cookie" ] ;
35- proxyRes . headers [ "cookies" ] = "" ; // 清除 cookies 头
26+ proxy . on ( "proxyRes" , ( proxyRes : unknown ) => {
27+ const res = proxyRes as { headers : Record < string , unknown > } ;
28+ delete res . headers [ "set-cookie" ] ;
29+ res . headers [ "cookies" ] = "" ;
3630 } ) ;
3731 } ,
38- } ,
39- } ,
32+ } ;
33+
34+ const javaProxyConfig = {
35+ target : "http://localhost:8080" ,
36+ changeOrigin : true ,
37+ secure : false ,
38+ configure : ( proxy : { on : ( event : string , handler : ( arg : unknown ) => void ) => void } ) => {
39+ proxy . on ( "proxyReq" , ( proxyReq : unknown ) => {
40+ ( proxyReq as { removeHeader : ( name : string ) => void } ) . removeHeader ( "referer" ) ;
41+ ( proxyReq as { removeHeader : ( name : string ) => void } ) . removeHeader ( "origin" ) ;
42+ } ) ;
43+ proxy . on ( "proxyRes" , ( proxyRes : unknown ) => {
44+ const res = proxyRes as { headers : Record < string , unknown > } ;
45+ delete res . headers [ "set-cookie" ] ;
46+ res . headers [ "cookies" ] = "" ;
47+ } ) ;
48+ } ,
49+ } ;
50+
51+ // Python 服务: rag, synthesis, annotation, evaluation, models
52+ const pythonPaths = [ "rag" , "synthesis" , "annotation" , "data-collection" , "evaluation" , "models" ] ;
53+ // Java 服务: data-management, knowledge-base
54+ const javaPaths = [ "data-management" , "knowledge-base" , "operators" ] ;
55+
56+ const proxy : Record < string , object > = { } ;
57+ for ( const p of pythonPaths ) {
58+ proxy [ `/api/${ p } ` ] = pythonProxyConfig ;
59+ }
60+ for ( const p of javaPaths ) {
61+ proxy [ `/api/${ p } ` ] = javaProxyConfig ;
62+ }
63+ return proxy ;
64+ } ) ( ) ,
4065 } ,
4166} ) ;
0 commit comments