2024-10-01 19:09:35 +07:00
|
|
|
import { dotenvLoad } from "dotenv-mono";
|
|
|
|
|
|
2026-02-13 15:52:13 +07:00
|
|
|
dotenvLoad();
|
2025-01-02 14:48:19 +07:00
|
|
|
|
2026-02-13 15:52:13 +07:00
|
|
|
import { Elysia } from "elysia";
|
|
|
|
|
import { auth } from "./lib/auth";
|
|
|
|
|
import { authPlugin } from "./lib/auth-plugin";
|
|
|
|
|
import { errorHandler } from "./lib/error-handler";
|
|
|
|
|
import { bootstrapRoutes } from "./routes/bootstrap";
|
|
|
|
|
import { k8sRoutes } from "./routes/k8s";
|
|
|
|
|
import { reverseProxyRoutes } from "./routes/reverse-proxy.routes";
|
|
|
|
|
import { serverRoutes } from "./routes/servers";
|
|
|
|
|
import { terminalRoutes } from "./routes/terminal";
|
|
|
|
|
import { userRoutes } from "./routes/users";
|
2025-01-02 14:48:19 +07:00
|
|
|
|
2026-02-13 15:52:13 +07:00
|
|
|
// Register event handlers
|
|
|
|
|
import "./infrastructure/event-handlers";
|
2025-06-01 16:27:34 +07:00
|
|
|
|
2024-09-21 13:28:02 +07:00
|
|
|
const app = new Elysia()
|
2026-02-13 15:52:13 +07:00
|
|
|
.use(errorHandler)
|
|
|
|
|
.onRequest(({ set }) => {
|
|
|
|
|
const origin = process.env.WEB_URL || "http://localhost:3001";
|
|
|
|
|
set.headers["Access-Control-Allow-Origin"] = origin;
|
|
|
|
|
set.headers["Access-Control-Allow-Credentials"] = "true";
|
|
|
|
|
set.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, PATCH, DELETE, OPTIONS";
|
|
|
|
|
set.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization, Cookie";
|
2025-06-01 16:27:34 +07:00
|
|
|
})
|
2026-02-13 15:52:13 +07:00
|
|
|
.options("/*", () => new Response(null, { status: 204 }))
|
|
|
|
|
.all("/auth/*", ({ request }) => auth.handler(request))
|
|
|
|
|
.use(bootstrapRoutes)
|
|
|
|
|
.use(authPlugin)
|
|
|
|
|
.group("/api", (app) =>
|
|
|
|
|
app.use(userRoutes).use(serverRoutes).use(reverseProxyRoutes).use(k8sRoutes).use(terminalRoutes)
|
2025-01-02 14:48:19 +07:00
|
|
|
)
|
2026-02-13 15:52:13 +07:00
|
|
|
.get("/health", () => ({ status: "ok" }));
|
2024-09-21 13:28:02 +07:00
|
|
|
|
|
|
|
|
export type App = typeof app;
|
2026-02-13 15:52:13 +07:00
|
|
|
|
|
|
|
|
app.listen(3000, () => {
|
|
|
|
|
console.log("Server running on http://localhost:3000");
|
|
|
|
|
});
|