| 1 | import * as Drizzle from "alchemy/Drizzle/Postgres"; |
| 2 | import * as Railway from "alchemy/Railway"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 5 | import { Db, Site } from "./shared.ts"; |
| 6 | |
| 7 | /** |
| 8 | * HTTP Service. Canvas Functions cap at 96KB and cannot hold |
| 9 | * Drizzle/pg; this image is built from `main` like {@link Api}. |
| 10 | * Binds the same {@link Db} via {@link Railway.ConnectPostgres}. |
| 11 | */ |
| 12 | export default class Ping extends Railway.Service<Ping>()( |
| 13 | "Ping", |
| 14 | { |
| 15 | project: Site, |
| 16 | main: import.meta.url, |
| 17 | port: 3000, |
| 18 | build: { install: ["pg"] }, |
| 19 | healthcheck: "/", |
| 20 | }, |
| 21 | Effect.gen(function* () { |
| 22 | const conn = yield* Railway.ConnectPostgres(Db); |
| 23 | const db = yield* Drizzle.Postgres(conn.connectionString); |
| 24 | return { |
| 25 | fetch: db.execute("select 1 as ok").pipe( |
| 26 | Effect.flatMap(HttpServerResponse.json), |
| 27 | Effect.catch((error) => |
| 28 | HttpServerResponse.json( |
| 29 | { ok: false, error: String(error) }, |
| 30 | { status: 500 }, |
| 31 | ), |
| 32 | ), |
| 33 | ), |
| 34 | }; |
| 35 | }).pipe(Effect.provide(Railway.ConnectPostgresHttp)), |
| 36 | ) {} |