HF-SaaS / app /node /server.js
luizcireno-crypto
docs: comprehensive documentation and inline comments across all files
85d93ea
raw
history blame
1.9 kB
// ============================================================
// 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);
});
});