| 1 | import * as Lambda from "@/AWS/Lambda"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | |
| 6 | const main = import.meta.url; |
| 7 | |
| 8 | export class TestFunction extends Lambda.Function<Lambda.Function>()( |
| 9 | "TestFunction", |
| 10 | ) {} |
| 11 | |
| 12 | export 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 | |
| 34 | export default TestFunctionLive; |