@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 41 lines 1.47 KB
Raw
1 import * as Lambda from "@alchemy.run/aws/Lambda";
2 import * as Config from "effect/Config";
3 import * as Effect from "effect/Effect";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6 import * as Option from "effect/Option";
7
8 const main = import.meta.url;
9
10 export class TestFunction extends Lambda.Function<Lambda.Function>()("TestFunction") {}
11
12 export const TestFunctionLive = TestFunction.make(
13 {
14 main,
15 functionUrl: true,
16 },
17 Effect.gen(function* () {
18 // Read at init through the runtime ConfigProvider; the env values are
19 // plain strings that look like JSON ("true", "3000").
20 const flag = yield* Config.option(Config.Boolean("CONFIG_FLAG"));
21 const port = yield* Config.option(Config.Number("CONFIG_PORT"));
22 return {
23 fetch: Effect.gen(function* () {
24 const request = yield* HttpServerRequest;
25 const pathname = yield* Effect.sync(() => new URL(request.originalUrl).pathname);
26 if (pathname === "/readiness") {
27 const marker = yield* Effect.sync(() => process.env.READINESS_MARKER);
28 return HttpServerResponse.text(marker ?? "missing");
29 }
30 if (pathname === "/config") {
31 return HttpServerResponse.text(
32 `${Option.getOrUndefined(flag)} ${Option.getOrUndefined(port)}`,
33 );
34 }
35 return HttpServerResponse.text("Hello, world!");
36 }),
37 };
38 }),
39 );
40
41 export default TestFunctionLive;