diff --git a/Dockerfile b/Dockerfile index 1b6419e..41f9c2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,20 @@ -FROM nginx:alpine +FROM denoland/deno:alpine-2.0.2 -# Remove default nginx static assets -RUN rm -rf /usr/share/nginx/html/* +WORKDIR /app -# Copy Custom NAS 3D CAD Viewer & Static Assets -COPY ./viewer /usr/share/nginx/html/viewer -COPY ./data /usr/share/nginx/html/data -COPY ./mechanical /usr/share/nginx/html/mechanical -COPY ./bom /usr/share/nginx/html/bom +# Cache dependencies +COPY deno.json . +RUN deno install || true -# Copy default landing redirect -RUN echo '
' > /usr/share/nginx/html/index.html - -# Copy optimized nginx configuration -COPY ./nginx.conf /etc/nginx/conf.d/default.conf +# Copy source code and assets +COPY main.ts . +COPY viewer ./viewer +COPY data ./data +COPY mechanical ./mechanical +COPY electrical ./electrical +# Expose port EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] + +# Run the Deno app +CMD ["task", "start"] diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..996d457 --- /dev/null +++ b/deno.json @@ -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" + } +} diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..4c824a1 --- /dev/null +++ b/main.ts @@ -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); diff --git a/nginx.conf b/nginx.conf deleted file mode 100644 index f69d358..0000000 --- a/nginx.conf +++ /dev/null @@ -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; - } -}