The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Drizzle from "@alchemy.run/drizzle/Postgres"; |
| 2 | import * as Railway from "@alchemy.run/railway"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { HttpServerRequest } from "effect/http/HttpServerRequest"; |
| 5 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 6 | import { Db } from "./postgres-shared.ts"; |
| 7 | import { Partition, Site } from "./suite-env.ts"; |
| 8 | |
| 9 | export { Db, Site }; |
| 10 | |
| 11 | export const POSTGRES_PORT = 3000; |
| 12 | |
| 13 | /** |
| 14 | * HTTP Service that binds Postgres via {@link Railway.ConnectPostgres} |
| 15 | * and answers SELECT 1. Never returns the connection string. |
| 16 | */ |
| 17 | export default class PostgresApi extends Railway.Service<PostgresApi>()( |
| 18 | "PostgresApi", |
| 19 | { |
| 20 | project: Site, |
| 21 | environment: Partition, |
| 22 | main: import.meta.url, |
| 23 | port: POSTGRES_PORT, |
| 24 | }, |
| 25 | Effect.gen(function* () { |
| 26 | const conn = yield* Railway.ConnectPostgres(Db); |
| 27 | const db = yield* Drizzle.Postgres(conn.connectionString); |
| 28 | |
| 29 | return { |
| 30 | fetch: Effect.gen(function* () { |
| 31 | const request = yield* HttpServerRequest; |
| 32 | const path = new URL(request.url, "http://service").pathname; |
| 33 | if (path === "/ping") { |
| 34 | return yield* HttpServerResponse.json({ ok: true }); |
| 35 | } |
| 36 | const rows = yield* db.execute("select 1 as ok", "objects"); |
| 37 | if (path === "/health" || path === "/") { |
| 38 | return yield* HttpServerResponse.json({ rows }); |
| 39 | } |
| 40 | return yield* HttpServerResponse.json({ rows }, { status: 404 }); |
| 41 | }).pipe( |
| 42 | Effect.catch((error) => |
| 43 | HttpServerResponse.json({ ok: false, error: String(error) }, { status: 500 }), |
| 44 | ), |
| 45 | ), |
| 46 | }; |
| 47 | }).pipe(Effect.provide(Railway.ConnectPostgresHttp)), |
| 48 | ) {} |