Skip to content
Source
Sign inSign up
Open History to see the last commit

http.ts

31 lines1.1 KB

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