File size: 1,902 Bytes
6af979f
85d93ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6af979f
 
 
 
 
 
 
85d93ea
6af979f
 
85d93ea
 
 
 
 
6af979f
 
 
85d93ea
 
 
 
 
 
6af979f
 
85d93ea
 
6af979f
 
 
 
 
 
 
85d93ea
6af979f
85d93ea
 
 
 
6af979f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ============================================================
//  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);
  });
});