1import * as Lambda from "@/AWS/Lambda";
2import * as Duration from "effect/Duration";
3import * as Effect from "effect/Effect";
4import { HttpServerRequest } from "effect/http/HttpServerRequest";
5import * as HttpServerResponse from "effect/http/HttpServerResponse";
6
7const main = import.meta.url;
8
9/** ALB Lambda target answering the `/api/*` path rule. */
10export class ApiTargetFunction extends Lambda.Function<Lambda.Function>()(
11 "ApiTargetFunction",
12) {}
13
14export const ApiTargetFunctionLive = ApiTargetFunction.make(
15 {
16 main,
17 timeout: Duration.seconds(30),
18 },
19 Effect.gen(function* () {
20 return {
21 fetch: Effect.gen(function* () {
22 const request = yield* HttpServerRequest;
23 const pathname = new URL(request.originalUrl).pathname;
24 return yield* HttpServerResponse.json({
25 target: "api",
26 path: pathname,
27 });
28 }).pipe(Effect.orDie),
29 };
30 }),
31);
32
33export default ApiTargetFunctionLive;