feat: Migrate backend from NGINX to Deno + Hono API framework

This commit is contained in:
Tyler G 2026-08-22 22:17:54 -07:00
parent 450debbc1c
commit 4df0499d14
4 changed files with 70 additions and 41 deletions

View File

@ -1,19 +1,20 @@
FROM nginx:alpine FROM denoland/deno:alpine-2.0.2
# Remove default nginx static assets WORKDIR /app
RUN rm -rf /usr/share/nginx/html/*
# Copy Custom NAS 3D CAD Viewer & Static Assets # Cache dependencies
COPY ./viewer /usr/share/nginx/html/viewer COPY deno.json .
COPY ./data /usr/share/nginx/html/data RUN deno install || true
COPY ./mechanical /usr/share/nginx/html/mechanical
COPY ./bom /usr/share/nginx/html/bom
# Copy default landing redirect # Copy source code and assets
RUN echo '<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/viewer/index.html"></head></html>' > /usr/share/nginx/html/index.html COPY main.ts .
COPY viewer ./viewer
# Copy optimized nginx configuration COPY data ./data
COPY ./nginx.conf /etc/nginx/conf.d/default.conf COPY mechanical ./mechanical
COPY electrical ./electrical
# Expose port
EXPOSE 80 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# Run the Deno app
CMD ["task", "start"]

9
deno.json Normal file
View File

@ -0,0 +1,9 @@
{
"tasks": {
"start": "deno run --allow-net --allow-read --allow-env main.ts"
},
"imports": {
"hono": "npm:hono@4.0.0",
"postgres": "https://deno.land/x/postgresjs@v3.4.4/mod.js"
}
}

46
main.ts Normal file
View File

@ -0,0 +1,46 @@
import { Hono } from "hono";
import { serveStatic } from "hono/deno";
import postgres from "postgres";
const app = new Hono();
// Connect to Postgres using env vars (fallback for dev)
const sql = postgres({
host: Deno.env.get("POSTGRES_HOST") || "db",
port: parseInt(Deno.env.get("POSTGRES_PORT") || "5432"),
database: Deno.env.get("POSTGRES_DB") || "nas_builder",
username: Deno.env.get("POSTGRES_USER") || "nasadmin",
password: Deno.env.get("POSTGRES_PASSWORD") || "your_secure_database_password_here",
});
// API Routes
app.get("/api/status", async (c) => {
try {
// Ping the database
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);
}
});
// Serve the 3D Viewer frontend
app.use("/*", serveStatic({ root: "./" }));
// Handle root redirect to viewer
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);

View File

@ -1,27 +0,0 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html /viewer/index.html;
# Enable gzip compression for CAD models, netlists & JSON catalogs
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml;
location / {
try_files $uri $uri/ /viewer/index.html;
}
# Cache static CAD assets and JSON catalogs
location ~* \.(json|dxf|scad|csv|stl|obj)$ {
expires 1d;
add_header Cache-Control "public, no-transform";
add_header Access-Control-Allow-Origin "*";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}