2024-01-29 23:36:12 +00:00
|
|
|
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";
|
2024-02-07 22:48:42 +00:00
|
|
|
import FileEventStore from "./infrastructure/FileEventStore";
|
|
|
|
import AppQueries from "./domain/AppQueries";
|
|
|
|
import AppProjections from "./domain/AppProjections";
|
2024-01-29 23:36:12 +00:00
|
|
|
|
2024-02-07 22:48:42 +00:00
|
|
|
// Domain
|
|
|
|
const eventStore = new FileEventStore("./data/events.jsonl");
|
|
|
|
const projections = new AppProjections();
|
|
|
|
const queries = new AppQueries(projections);
|
2024-01-29 23:36:12 +00:00
|
|
|
|
2024-02-07 22:48:42 +00:00
|
|
|
projections.getAll().forEach((projection) => {
|
|
|
|
eventStore.subscribe(projection);
|
|
|
|
});
|
2024-03-10 09:49:36 +00:00
|
|
|
// @ts-ignore Bun handles top-level await
|
2024-02-07 22:48:42 +00:00
|
|
|
await eventStore.replay();
|
|
|
|
|
|
|
|
// External services
|
2024-01-29 23:36:12 +00:00
|
|
|
const caprover = new Caprover(
|
2024-02-07 22:48:42 +00:00
|
|
|
eventStore,
|
2024-01-29 23:36:12 +00:00
|
|
|
process.env.CAPTAIN_DOMAIN,
|
|
|
|
process.env.CAPTAIN_PASSWORD
|
|
|
|
);
|
|
|
|
const dockerHub = new DockerHub();
|
|
|
|
|
|
|
|
const server = Bun.serve({
|
|
|
|
port: 3000,
|
|
|
|
fetch(req: Request) {
|
|
|
|
const url = new URL(req.url);
|
|
|
|
switch (url.pathname) {
|
|
|
|
case "/":
|
|
|
|
return new Response(
|
|
|
|
Layout(
|
|
|
|
html`<h1>Hello World.</h1>
|
|
|
|
<p>I'm Joe, your personal assistant.</p>`
|
|
|
|
),
|
|
|
|
{ headers: { "Content-Type": "text/html" } }
|
|
|
|
);
|
|
|
|
case "/applications":
|
2024-03-10 08:49:52 +00:00
|
|
|
return applications(req, caprover, queries);
|
2024-01-29 23:36:12 +00:00
|
|
|
case "/applications/update":
|
2024-02-07 22:48:42 +00:00
|
|
|
return applicationsUpdate(req, caprover, dockerHub, queries);
|
2024-01-29 23:36:12 +00:00
|
|
|
default:
|
|
|
|
return new Response("Not Found", { status: 404 });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(`Server started at http://${server.hostname}:${server.port}`);
|