@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 06:00 UTC

main
ts 56 lines 1.69 KB
Raw
1 import * as Effect from "effect/Effect";
2 import { HttpServerRequest } from "effect/http/HttpServerRequest";
3 import * as HttpServerResponse from "effect/http/HttpServerResponse";
4 import * as Option from "effect/Option";
5
6 export const TestHttpEffect = Effect.gen(function* () {
7 const request = yield* HttpServerRequest;
8 const url = new URL(request.originalUrl);
9 const pathname = url.pathname;
10
11 if (request.method === "GET" && pathname === "/inspect") {
12 return yield* HttpServerResponse.json({
13 method: request.method,
14 url: request.url,
15 originalUrl: request.originalUrl,
16 host: request.headers.host,
17 protocol: request.headers["x-forwarded-proto"],
18 requestId: request.headers["x-request-id"],
19 remoteAddress: Option.getOrUndefined(request.remoteAddress),
20 query: Object.fromEntries(url.searchParams.entries()),
21 cookies: request.cookies,
22 });
23 }
24
25 if (request.method === "POST" && pathname === "/jobs") {
26 const payload = (yield* request.json) as { content: string };
27 const response = yield* HttpServerResponse.json(
28 {
29 method: request.method,
30 url: request.url,
31 payload,
32 },
33 {
34 status: 201,
35 headers: {
36 "x-handler": "lambda-http",
37 },
38 },
39 );
40
41 return HttpServerResponse.setCookieUnsafe(response, "job-session", "created", {
42 httpOnly: true,
43 path: "/",
44 });
45 }
46
47 if (request.method === "GET" && pathname === "/binary") {
48 return HttpServerResponse.uint8Array(new TextEncoder().encode("alchemy"), {
49 headers: {
50 "content-type": "application/octet-stream",
51 },
52 });
53 }
54
55 return HttpServerResponse.text("Not found", { status: 404 });
56 });