| 1 | import * as Http from "alchemy/Http"; |
| 2 | import * as Config from "effect/Config"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as HttpApiBuilder from "effect/http-api/HttpApiBuilder"; |
| 6 | import { Api } from "./api.ts"; |
| 7 | import { CurrentUser } from "./current-user.ts"; |
| 8 | import { Authentication } from "./middleware.ts"; |
| 9 | |
| 10 | export const PublicLive = HttpApiBuilder.group(Api, "public", (handlers) => |
| 11 | Effect.gen(function* () { |
| 12 | const github = yield* Config.Boolean("GITHUB_ENABLED").pipe( |
| 13 | Config.withDefault(false), |
| 14 | ); |
| 15 | return handlers |
| 16 | .handle("health", () => Effect.succeed({ ok: true as const })) |
| 17 | .handle("providers", () => Effect.succeed({ github })); |
| 18 | }), |
| 19 | ); |
| 20 | |
| 21 | export const PrivateLive = HttpApiBuilder.group(Api, "private", (handlers) => |
| 22 | handlers.handle("me", () => |
| 23 | Effect.gen(function* () { |
| 24 | return yield* CurrentUser; |
| 25 | }), |
| 26 | ), |
| 27 | ); |
| 28 | |
| 29 | export const HttpLive = HttpApiBuilder.layer(Api).pipe( |
| 30 | Layer.provide([PublicLive, PrivateLive]), |
| 31 | Layer.provide(Authentication.layer), |
| 32 | Layer.provide(Http.Platform), |
| 33 | ); |