Spaces:
Sleeping
Sleeping
Commit
·
7423461
1
Parent(s):
6c771b7
add: huggingface docker
Browse files
server.js
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require("express");
|
2 |
+
const path = require("path");
|
3 |
+
const app = express();
|
4 |
+
|
5 |
+
// Set the port to 7860 as required by Hugging Face Spaces
|
6 |
+
const PORT = process.env.PORT || 7860;
|
7 |
+
const HOST = process.env.HOST || "0.0.0.0";
|
8 |
+
|
9 |
+
// Serve static files from the dist directory
|
10 |
+
app.use(express.static(path.join(__dirname, "dist")));
|
11 |
+
|
12 |
+
// Health check endpoint for Hugging Face Spaces (must come before wildcard route)
|
13 |
+
app.get("/health", (_req, res) => {
|
14 |
+
res.status(200).send("healthy");
|
15 |
+
});
|
16 |
+
|
17 |
+
// Handle SPA routing - serve index.html for all routes
|
18 |
+
app.get("*", (_req, res) => {
|
19 |
+
res.sendFile(path.join(__dirname, "dist", "index.html"));
|
20 |
+
});
|
21 |
+
|
22 |
+
// Start the server
|
23 |
+
app.listen(PORT, HOST, () => {
|
24 |
+
console.log(`Server is running on ${HOST}:${PORT}`);
|
25 |
+
console.log(`Access the application at http://localhost:${PORT}`);
|
26 |
+
});
|
27 |
+
|
28 |
+
// Handle graceful shutdown
|
29 |
+
process.on("SIGTERM", () => {
|
30 |
+
console.log("SIGTERM received, shutting down gracefully");
|
31 |
+
process.exit(0);
|
32 |
+
});
|
33 |
+
|
34 |
+
process.on("SIGINT", () => {
|
35 |
+
console.log("SIGINT received, shutting down gracefully");
|
36 |
+
process.exit(0);
|
37 |
+
});
|