@@ -47,6 +47,43 @@ const isWebBuild = process.env.WEB_BUILD === "1"
47
47
// eslint-disable-next-line no-console
48
48
console . log ( green ( "Build type:" ) , isWebBuild ? "Web" : "Unknown" )
49
49
50
+ const proxyConfig = {
51
+ target : "http://localhost:2234" ,
52
+ changeOrigin : true ,
53
+ selfHandleResponse : true ,
54
+ configure : ( proxy , _options ) => {
55
+ proxy . on ( "proxyRes" , ( proxyRes , req , res ) => {
56
+ const body = [ ] as any [ ]
57
+ proxyRes . on ( "data" , ( chunk : any ) => body . push ( chunk ) )
58
+ proxyRes . on ( "end" , ( ) => {
59
+ const html = parseHTML ( Buffer . concat ( body ) . toString ( ) )
60
+ const doc = html . document
61
+
62
+ const $scripts = doc . querySelectorAll ( "script" )
63
+ $scripts . forEach ( ( script ) => {
64
+ const src = script . getAttribute ( "src" )
65
+ if ( src ) {
66
+ script . setAttribute ( "src" , `http://localhost:2234${ src } ` )
67
+ }
68
+ } )
69
+
70
+ const $links = doc . querySelectorAll ( "link" )
71
+ $links . forEach ( ( link ) => {
72
+ const href = link . getAttribute ( "href" )
73
+ if ( href ) {
74
+ link . setAttribute ( "href" , `http://localhost:2234${ href } ` )
75
+ }
76
+ } )
77
+
78
+ res . setHeader ( "Content-Type" , "text/html; charset=utf-8" )
79
+
80
+ const modifiedHtml = doc . toString ( )
81
+ res . end ( modifiedHtml )
82
+ } )
83
+ } )
84
+ } ,
85
+ }
86
+
50
87
export default ( { mode } ) => {
51
88
const env = loadEnv ( mode , process . cwd ( ) )
52
89
const typedEnv = env as typeof EnvType
@@ -73,42 +110,10 @@ export default ({ mode }) => {
73
110
} ,
74
111
cors : true ,
75
112
proxy : {
76
- "/login" : {
77
- target : "http://localhost:2234" ,
78
- changeOrigin : true ,
79
- selfHandleResponse : true ,
80
- configure : ( proxy , _options ) => {
81
- proxy . on ( "proxyRes" , ( proxyRes , req , res ) => {
82
- const body = [ ] as any [ ]
83
- proxyRes . on ( "data" , ( chunk : any ) => body . push ( chunk ) )
84
- proxyRes . on ( "end" , ( ) => {
85
- const html = parseHTML ( Buffer . concat ( body ) . toString ( ) )
86
- const doc = html . document
87
-
88
- const $scripts = doc . querySelectorAll ( "script" )
89
- $scripts . forEach ( ( script ) => {
90
- const src = script . getAttribute ( "src" )
91
- if ( src ) {
92
- script . setAttribute ( "src" , `http://localhost:2234${ src } ` )
93
- }
94
- } )
95
-
96
- const $links = doc . querySelectorAll ( "link" )
97
- $links . forEach ( ( link ) => {
98
- const href = link . getAttribute ( "href" )
99
- if ( href ) {
100
- link . setAttribute ( "href" , `http://localhost:2234${ href } ` )
101
- }
102
- } )
103
-
104
- res . setHeader ( "Content-Type" , "text/html; charset=utf-8" )
105
-
106
- const modifiedHtml = doc . toString ( )
107
- res . end ( modifiedHtml )
108
- } )
109
- } )
110
- } ,
111
- } ,
113
+ "/login" : proxyConfig ,
114
+ "/forget-password" : proxyConfig ,
115
+ "/reset-password" : proxyConfig ,
116
+ "/register" : proxyConfig ,
112
117
113
118
...( env . VITE_DEV_PROXY
114
119
? {
0 commit comments