custom-nas/main.ts

38 lines
1015 B
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";
const app = new Hono();
// Initialize DB schema on startup
await initDb();
// 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);
// 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);