t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Hetzner/fixtures/api.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

43 lines
1.4 KiB
TypeScript

import * as Hetzner from "@/Hetzner";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import { HttpServerRequest } from "effect/http/HttpServerRequest";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { API_PORT, Box, Data, MARKER_FILE, VOLUME_PATH } from "./shared.ts";
/**
* HTTP Service: mounts the same Volume as {@link Worker} and serves the
* marker file Worker writes.
*/
export default class Api extends Hetzner.Service<Api>()(
"Api",
{
server: Box,
main: import.meta.url,
port: API_PORT,
},
Effect.gen(function* () {
const volume = yield* Data;
const mount = yield* Hetzner.MountVolume(volume, { path: VOLUME_PATH });
return {
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
const url = new URL(request.url, "http://service");
if (url.pathname === "/health") {
return yield* HttpServerResponse.json({
ok: true,
path: mount.path,
});
}
const fs = yield* FileSystem.FileSystem;
const text = yield* fs.readFileString(MARKER_FILE).pipe(Effect.orDie);
return yield* HttpServerResponse.json({
path: mount.path,
device: mount.device,
text,
});
}),
};
}).pipe(Effect.provide(Hetzner.MountVolumeLive)),
) {}