// ============================================================ // HF-VPS — Node.js Server (optional layer) // // This server is DISABLED BY DEFAULT. // To enable: set autostart=true in config/supervisord.conf // // When enabled: // - Runs internally on port 3000 // - Accessible externally at /node/ via Nginx reverse proxy // - Nginx strips the /node/ prefix before forwarding to this server // // HOW TO USE: // 1. Edit this file with your Node.js app logic // 2. Set autostart=true in config/supervisord.conf // 3. Rebuild and push to HF // // Environment variables: // NODE_PORT — port to listen on (default: 3000, must match supervisord/nginx) // ============================================================ const http = require("http"); const PORT = process.env.NODE_PORT || 3000; const server = http.createServer((req, res) => { // Health check — used by Nginx and monitoring if (req.url === "/health") { res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ status: "ok", runtime: "node", uptime: process.uptime(), })); return; } // Default handler — replace with your application logic // Examples: // - Express/Fastify app // - WebSocket server // - Puppeteer/Playwright automation // - Serve a Next.js/React build res.writeHead(200, { "Content-Type": "application/json" }); res.end(JSON.stringify({ message: "Node.js layer is running", hint: "Edit app/node/server.js to add your logic. Enable in config/supervisord.conf.", })); }); server.listen(PORT, "0.0.0.0", () => { console.log(`[node] server running on port ${PORT}`); }); // Graceful shutdown — supervisord sends SIGTERM before stopping the process process.on("SIGTERM", () => { server.close(() => { console.log("[node] server stopped cleanly"); process.exit(0); }); });