@@ -2,96 +2,6 @@ import react from '@vitejs/plugin-react';
22import { defineConfig , loadEnv } from 'vite' ;
33import svgr from 'vite-plugin-svgr' ;
44
5- /**
6- * Vite-only plugin that creates a dynamic WebSocket reverse-proxy for the
7- * debug session endpoint. Because the backend picks a random port in the
8- * range 65435-65535 for each session, a static proxy target is not possible.
9- *
10- * Flow (dev only):
11- * 1. Browser calls POST /debug/ws-register with the wss:// URL returned by
12- * the debugSession API, telling the plugin which host:port to tunnel to.
13- * 2. Browser dials ws://localhost:<vite-port>/debug/join (same origin, no
14- * cert issues).
15- * 3. This plugin intercepts the WebSocket upgrade, opens a TLS tunnel to
16- * the registered target, and splices the two sockets together.
17- */
18- // function dynamicWsProxyPlugin(): Plugin {
19- // let registeredTarget: URL | null = null;
20-
21- // return {
22- // name: 'dynamic-ws-proxy',
23- // configureServer(server) {
24- // // ── Registration endpoint ─────────────────────────────────────────────
25- // server.middlewares.use('/debug/ws-register', (req, res) => {
26- // if (req.method !== 'POST') {
27- // res.statusCode = 405;
28- // res.end();
29- // return;
30- // }
31- // let body = '';
32- // req.on('data', (chunk: Buffer) => (body += chunk.toString()));
33- // req.on('end', () => {
34- // try {
35- // const { url } = JSON.parse(body) as { url: string };
36- // registeredTarget = new URL(url);
37- // res.statusCode = 200;
38- // res.setHeader('Content-Type', 'application/json');
39- // res.end(JSON.stringify({ ok: true }));
40- // } catch {
41- // res.statusCode = 400;
42- // res.end(JSON.stringify({ error: 'Invalid request body' }));
43- // }
44- // });
45- // });
46-
47- // // ── Dynamic WebSocket tunnel ──────────────────────────────────────────
48- // server.httpServer?.prependListener(
49- // 'upgrade',
50- // (req: IncomingMessage, socket: any, head: Buffer) => {
51- // if (!req.url?.startsWith('/debug/join') || !registeredTarget) return;
52-
53- // const target = registeredTarget;
54- // const useSecure =
55- // target.protocol === 'wss:' || target.protocol === 'https:';
56- // const port = target.port
57- // ? parseInt(target.port, 10)
58- // : useSecure ? 443 : 80;
59-
60- // const upstream: net.Socket = useSecure
61- // ? tls.connect({ host: target.hostname, port, rejectUnauthorized: false })
62- // : net.createConnection({ host: target.hostname, port });
63-
64- // upstream.once(useSecure ? 'secureConnect' : 'connect', () => {
65- // // Re-emit the full HTTP Upgrade request to the upstream server
66- // const headerLines = [
67- // `GET ${req.url} HTTP/1.1`,
68- // `Host: ${target.host}`,
69- // ...Object.entries(req.headers)
70- // .filter(([k]) => k !== 'host')
71- // .map(([k, v]) => `${k}: ${Array.isArray(v) ? v.join(', ') : (v ?? '')}` ),
72- // '',
73- // '',
74- // ];
75- // upstream.write(headerLines.join('\r\n'));
76- // if (head?.length) upstream.write(head);
77-
78- // socket.pipe(upstream);
79- // upstream.pipe(socket);
80- // });
81-
82- // upstream.on('error', (err: Error) => {
83- // console.error('[dynamic-ws-proxy] upstream error:', err.message);
84- // socket.destroy();
85- // });
86- // socket.on('error', () => upstream.destroy());
87- // socket.on('close', () => upstream.destroy());
88- // upstream.on('close', () => socket.destroy());
89- // },
90- // );
91- // },
92- // };
93- // }
94-
955export default defineConfig ( ( { mode } ) => {
966 const env = loadEnv ( mode , process . cwd ( ) , '' ) ;
977
@@ -101,7 +11,7 @@ export default defineConfig(({ mode }) => {
10111 }
10212
10313 return {
104- base : '/debug/' ,
14+ base : '/cws/ debug/' ,
10515 plugins : [ react ( ) , svgr ( { include : '**/*.svg' , svgrOptions : { exportType : 'named' } } ) ] ,
10616 server : {
10717 proxy : programHost
0 commit comments