The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
| 1 | // A Vite plugin that serves its own WebSockets on the dev server, as |
| 2 | // `@foldkit/vite-plugin` serves its DevTools relay (#2191). The Worker has |
| 3 | // no route for the paths, so the dev server must leave the sockets to the |
| 4 | // plugin: `/__echo` is taken at once, `/__echo-async` only after an `await` |
| 5 | // (as Vite's `server.proxy` awaits its `bypass`), once the Worker has |
| 6 | // already answered. |
| 7 | import type { Plugin } from "vite"; |
| 8 | import { WebSocketServer } from "ws"; |
| 9 | |
| 10 | const echoPlugin: Plugin = { |
| 11 | name: "ws-echo", |
| 12 | configureServer(server) { |
| 13 | const wss = new WebSocketServer({ noServer: true }); |
| 14 | server.httpServer?.on("upgrade", async (request, socket, head) => { |
| 15 | if (request.url !== "/__echo" && request.url !== "/__echo-async") return; |
| 16 | if (request.url === "/__echo-async") { |
| 17 | await new Promise((resolve) => setTimeout(resolve, 500)); |
| 18 | } |
| 19 | wss.handleUpgrade(request, socket, head, (ws) => { |
| 20 | ws.on("message", (data) => ws.send(`echo ${data}`)); |
| 21 | }); |
| 22 | }); |
| 23 | }, |
| 24 | }; |
| 25 | |
| 26 | export default { plugins: [echoPlugin] }; |