1import * as Fly from "@/Fly";
2import * as Effect from "effect/Effect";
3import { HttpServerRequest } from "effect/http/HttpServerRequest";
4import * as HttpServerResponse from "effect/http/HttpServerResponse";
5import { API_PORT } from "./shared.ts";
6
7export const ChecksSite = Fly.App("ChecksSite");
8
9export default class ChecksApi extends Fly.Service<ChecksApi>()(
10 "ChecksApi",
11 {
12 app: ChecksSite,
13 main: import.meta.url,
14 region: "iad",
15 port: API_PORT,
16 services: [
17 {
18 protocol: "tcp",
19 internalPort: API_PORT,
20 autostart: true,
21 autostop: "off",
22 minMachinesRunning: 1,
23 ports: [
24 { port: 80, handlers: ["http"], forceHttps: true },
25 { port: 443, handlers: ["tls", "http"] },
26 ],
27 checks: [
28 {
29 type: "http",
30 port: API_PORT,
31 method: "GET",
32 path: "/health",
33 protocol: "http",
34 interval: "15s",
35 timeout: "3s",
36 gracePeriod: "20s",
37 },
38 ],
39 },
40 ],
41 },
42 Effect.gen(function* () {
43 return {
44 fetch: Effect.gen(function* () {
45 const request = yield* HttpServerRequest;
46 const path = new URL(request.url, "http://service").pathname;
47 return path === "/health"
48 ? yield* HttpServerResponse.json({ ok: true })
49 : HttpServerResponse.empty({ status: 404 });
50 }),
51 };
52 }),
53) {}