50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { Hono } from "hono";
|
|
import { serveStatic } from "hono/deno";
|
|
import { sql, initDb } from "./src/db/connection.ts";
|
|
import { qaRoutes } from "./src/routes/qa.ts";
|
|
import { bomRoutes } from "./src/routes/bom.ts";
|
|
import { printFarmRoutes } from "./src/routes/printfarm.ts";
|
|
import { travelerRoutes } from "./src/routes/traveler.ts";
|
|
import { hilRoutes } from "./src/routes/hil.ts";
|
|
import { configExportRoutes } from "./src/routes/config_export.ts";
|
|
import { noteRoutes } from "./src/routes/notes.ts";
|
|
|
|
const app = new Hono();
|
|
|
|
// Initialize DB schema in background so server opens port immediately
|
|
initDb().catch((err) => console.error("Database background init failed:", err));
|
|
|
|
// API Routes
|
|
app.get("/api/status", async (c) => {
|
|
try {
|
|
const result = await sql`SELECT version()`;
|
|
return c.json({
|
|
status: "online",
|
|
database: "connected",
|
|
db_version: result[0].version,
|
|
timestamp: new Date().toISOString()
|
|
});
|
|
} catch (error: any) {
|
|
return c.json({ status: "online", database: "disconnected", error: error.message }, 500);
|
|
}
|
|
});
|
|
|
|
// Mount modular sub-routes
|
|
app.route("/api/qa", qaRoutes);
|
|
app.route("/api/bom", bomRoutes);
|
|
app.route("/api/print-farm", printFarmRoutes);
|
|
app.route("/api/travelers", travelerRoutes);
|
|
app.route("/api/hil", hilRoutes);
|
|
app.route("/api/config", configExportRoutes);
|
|
app.route("/api/notes", noteRoutes);
|
|
|
|
// Serve the 3D Viewer frontend
|
|
app.use("/*", serveStatic({ root: "./" }));
|
|
app.get("/", (c) => c.redirect("/viewer/index.html"));
|
|
|
|
// Start the server
|
|
const port = parseInt(Deno.env.get("PORT") || "80");
|
|
console.log(`🚀 NAS-Builder Deno API starting on port ${port}...`);
|
|
|
|
Deno.serve({ port }, app.fetch);
|