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); });