Spaces:
Sleeping
Sleeping
Download server.js from anuragshas/invoice-generator: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/anuragshas/invoice-generator/resolve/main/server.js
- Command line
-
hf download hf://spaces/anuragshas/invoice-generator/server.js
-
curl -L -o server.js https://huggingface.co/spaces/anuragshas/invoice-generator/resolve/main/server.js
1.1 kB
| 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); | |
| }); | |