File size: 1,096 Bytes
7423461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const express = require("express");
const path = require("path");
const app = express();

// Set the port to 7860 as required by Hugging Face Spaces
const PORT = process.env.PORT || 7860;
const HOST = process.env.HOST || "0.0.0.0";

// Serve static files from the dist directory
app.use(express.static(path.join(__dirname, "dist")));

// Health check endpoint for Hugging Face Spaces (must come before wildcard route)
app.get("/health", (_req, res) => {
    res.status(200).send("healthy");
});

// Handle SPA routing - serve index.html for all routes
app.get("*", (_req, res) => {
    res.sendFile(path.join(__dirname, "dist", "index.html"));
});

// Start the server
app.listen(PORT, HOST, () => {
    console.log(`Server is running on ${HOST}:${PORT}`);
    console.log(`Access the application at http://localhost:${PORT}`);
});

// Handle graceful shutdown
process.on("SIGTERM", () => {
    console.log("SIGTERM received, shutting down gracefully");
    process.exit(0);
});

process.on("SIGINT", () => {
    console.log("SIGINT received, shutting down gracefully");
    process.exit(0);
});