1import * as Lambda from "@/AWS/Lambda";
2import * as Effect from "effect/Effect";
3import { HttpServerRequest } from "effect/http/HttpServerRequest";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5
6const main = import.meta.url;
7
8export class TestFunction extends Lambda.Function<Lambda.Function>()(
9 "TestFunction",
10) {}
11
12export const TestFunctionLive = TestFunction.make(
13 {
14 main,
15 functionUrl: true,
16 },
17 Effect.gen(function* () {
18 return {
19 fetch: Effect.gen(function* () {
20 const request = yield* HttpServerRequest;
21 const pathname = yield* Effect.sync(
22 () => new URL(request.originalUrl).pathname,
23 );
24 if (pathname === "/readiness") {
25 const marker = yield* Effect.sync(() => process.env.READINESS_MARKER);
26 return HttpServerResponse.text(marker ?? "missing");
27 }
28 return HttpServerResponse.text("Hello, world!");
29 }),
30 };
31 }),
32);
33
34export default TestFunctionLive;