import Caprover from "./services/Caprover"; import applications from "./routes/applications"; import applicationsUpdate from "./routes/applications.update"; import Layout, { html } from "./ui/Layout"; import DockerHub from "./services/DockerHub"; import Human from "./services/Human"; import FileEventStore from "./infrastructure/FileEventStore"; import AppQueries from "./domain/AppQueries"; import AppProjections from "./domain/AppProjections"; // Domain const eventStore = new FileEventStore("./data/events.jsonl"); const projections = new AppProjections(); const queries = new AppQueries(projections); projections.getAll().forEach((projection) => { eventStore.subscribe(projection); }); // @ts-ignore Bun handles top-level await await eventStore.replay(); // External services const caprover = new Caprover( eventStore, process.env.CAPTAIN_DOMAIN, process.env.CAPTAIN_PASSWORD ); const dockerHub = new DockerHub(); const human = new Human(eventStore); const server = Bun.serve({ port: 3000, fetch(req: Request) { const url = new URL(req.url); switch (url.pathname) { case "/": return new Response( Layout( html`

Hello World.

I'm Joe, your personal assistant.

` ), { headers: { "Content-Type": "text/html" } } ); case "/applications": return applications(req, caprover, queries); case "/applications/update": return applicationsUpdate(req, caprover, dockerHub, human, queries); default: return new Response("Not Found", { status: 404 }); } }, }); console.log(`Server started at http://${server.hostname}:${server.port}`);