Skip to content

Commit 12304a5

Browse files
authored
let vite be the proxy to the dev server (#1630)
1 parent f759f8d commit 12304a5

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

apps/client/src/externals.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ function resolveUrl(protocol: 'http' | 'ws', path: string) {
4949
url.pathname = baseURI ? `${baseURI}/${path}` : path;
5050

5151
// in development mode, we use the React port for UI, but need the requests to target the server
52-
if (isDev) {
53-
// this is used as a fallback port for development
54-
url.port = '4001';
55-
}
52+
// this is done with a proxy in the vite config to avoid CORS issues in the dev environment
5653

5754
const result = url.toString();
5855

apps/client/vite.config.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ export default defineConfig({
3939
],
4040
server: {
4141
port: 3000,
42+
proxy: {
43+
'^/login*': {
44+
target: 'http://localhost:4001/',
45+
changeOrigin: true,
46+
configure: logProxyRequests,
47+
},
48+
'^/data*': {
49+
target: 'http://localhost:4001/',
50+
changeOrigin: true,
51+
configure: logProxyRequests,
52+
},
53+
'^/api*': {
54+
target: 'http://localhost:4001/',
55+
changeOrigin: true,
56+
configure: logProxyRequests,
57+
},
58+
'^/ws*': {
59+
target: 'http://localhost:4001/',
60+
changeOrigin: true,
61+
configure: logProxyRequests,
62+
ws: true,
63+
},
64+
},
4265
},
4366
test: {
4467
globals: true,
@@ -78,3 +101,9 @@ export default defineConfig({
78101
},
79102
},
80103
});
104+
105+
function logProxyRequests(proxy) {
106+
proxy.on('proxyReq', (_proxyReq, req, _res) => {
107+
console.log('Proxy:', req.method, req.url);
108+
});
109+
}

0 commit comments

Comments
 (0)