MCPcopy Create free account
hub / github.com/cloudflare/computer / fetch

Method fetch

packages/computer/src/proxy.ts:65–101  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

63
64export class WorkspaceProxy extends WorkerEntrypoint<unknown, WorkspaceProxyProps> {
65 override async fetch(request: Request): Promise<Response> {
66 const url = new URL(request.url);
67
68 const callback = url.pathname.match(/^\/__workspace_connect\/([0-9a-f-]{36})\/(health|ws)$/);
69 if (callback?.[2] === "health") {
70 return new Response("ok\n", {
71 headers: { "content-type": "text/plain; charset=utf-8" },
72 });
73 }
74
75 if (url.pathname === "/health") {
76 return new Response("ok\n", {
77 headers: { "content-type": "text/plain; charset=utf-8" },
78 });
79 }
80
81 if (url.pathname === "/ws" || callback?.[2] === "ws") {
82 if (callback?.[1]) {
83 url.pathname = "/ws";
84 url.searchParams.set("token", callback[1]);
85 request = new Request(url, request);
86 }
87 const { binding, id } = this.ctx.props;
88 const ns = (this.env as Record<string, unknown>)[binding] as
89 | DurableObjectNamespace
90 | undefined;
91 if (!ns) {
92 return new Response(`WorkspaceProxy: env.${binding} is not a DurableObjectNamespace`, {
93 status: 500,
94 });
95 }
96 const stub = ns.get(ns.idFromString(id));
97 return stub.fetch(request);
98 }
99
100 return new Response("not found", { status: 404 });
101 }
102}
103
104export class ArtifactsCLITarget extends RpcTarget {

Callers

nothing calls this directly

Calls 3

setMethod · 0.65
getMethod · 0.65
fetchMethod · 0.65

Tested by

no test coverage detected