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, 04:45 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import { DEFAULT_COMPATIBILITY_DATE } from "./internal/constants.ts"; |
| 3 | import * as Plugin from "./Plugin.ts"; |
| 4 | import { Runtime } from "./Runtime.ts"; |
| 5 | |
| 6 | class HttpServer extends Plugin.Service<HttpServer>()("cloudflare-runtime/plugin/HttpServer") {} |
| 7 | |
| 8 | /** |
| 9 | * Publish an HTTP dev server under a Worker name for local service bindings. |
| 10 | * The scoped Worker forwards to a fixed upstream address through workerd's |
| 11 | * HTTP service, preserving the original request URL, headers, streaming body, |
| 12 | * and WebSocket upgrades. Its registry entry is removed on shutdown. |
| 13 | */ |
| 14 | export const registerHttpServer = (name: string, url: URL) => |
| 15 | Effect.flatMap(Runtime, (runtime) => |
| 16 | runtime |
| 17 | .start({ |
| 18 | name, |
| 19 | compatibilityDate: DEFAULT_COMPATIBILITY_DATE, |
| 20 | compatibilityFlags: [], |
| 21 | cache: false, |
| 22 | bindings: [ |
| 23 | Plugin.useSync(HttpServer, () => ({ |
| 24 | name: "SERVER", |
| 25 | service: { name: "http-dev-server" }, |
| 26 | })), |
| 27 | ], |
| 28 | modules: [ |
| 29 | { |
| 30 | name: "http-dev-server.js", |
| 31 | type: "ESModule", |
| 32 | content: `export default { |
| 33 | fetch(request, env) { return env.SERVER.fetch(request); } |
| 34 | };`, |
| 35 | }, |
| 36 | ], |
| 37 | }) |
| 38 | .pipe( |
| 39 | Effect.provideService( |
| 40 | HttpServer, |
| 41 | HttpServer.of({ |
| 42 | services: [ |
| 43 | { |
| 44 | name: "http-dev-server", |
| 45 | external: { |
| 46 | address: `${url.hostname}:${url.port || (url.protocol === "https:" ? "443" : "80")}`, |
| 47 | ...(url.protocol === "https:" |
| 48 | ? { |
| 49 | https: { |
| 50 | options: { |
| 51 | forwardedProtoHeader: "X-Forwarded-Proto", |
| 52 | }, |
| 53 | }, |
| 54 | } |
| 55 | : { http: { forwardedProtoHeader: "X-Forwarded-Proto" } }), |
| 56 | }, |
| 57 | }, |
| 58 | ], |
| 59 | }), |
| 60 | ), |
| 61 | ), |
| 62 | ); |