Upload 4 files
Browse files- .dockerignore +5 -0
- Dockerfile +12 -0
- package.json +13 -0
- server.js +56 -0
.dockerignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node_modules
|
| 2 |
+
npm-debug.log
|
| 3 |
+
.git
|
| 4 |
+
.dockerignore
|
| 5 |
+
Dockerfile
|
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:18-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY package*.json ./
|
| 6 |
+
RUN npm install
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["npm", "start"]
|
package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "huggingface-keep-alive",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "A simple Node.js app to keep a Hugging Face Space alive",
|
| 5 |
+
"main": "server.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "node server.js"
|
| 8 |
+
},
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"express": "^4.18.2",
|
| 11 |
+
"axios": "^1.6.2"
|
| 12 |
+
}
|
| 13 |
+
}
|
server.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const axios = require('axios');
|
| 3 |
+
const app = express();
|
| 4 |
+
const PORT = process.env.PORT || 7860;
|
| 5 |
+
|
| 6 |
+
// URL de ce Space (sera configurée via variable d'environnement ou détectée)
|
| 7 |
+
const SPACE_URL = process.env.SPACE_URL;
|
| 8 |
+
|
| 9 |
+
app.get('/', (req, res) => {
|
| 10 |
+
res.send(`
|
| 11 |
+
<html>
|
| 12 |
+
<head>
|
| 13 |
+
<title>Persistent Space Keep-Alive</title>
|
| 14 |
+
<style>
|
| 15 |
+
body { font-family: sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: #f0f2f5; }
|
| 16 |
+
.card { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; }
|
| 17 |
+
h1 { color: #2d3436; }
|
| 18 |
+
p { color: #636e72; }
|
| 19 |
+
.status { font-weight: bold; color: #00b894; }
|
| 20 |
+
</style>
|
| 21 |
+
</head>
|
| 22 |
+
<body>
|
| 23 |
+
<div class="card">
|
| 24 |
+
<h1>Space Persistant Actif</h1>
|
| 25 |
+
<p>Ce Space est configuré pour rester éveillé.</p>
|
| 26 |
+
<p>Statut: <span class="status">En ligne 24/7</span></p>
|
| 27 |
+
<hr>
|
| 28 |
+
<p><small>Dernier auto-ping: ${new Date().toISOString()}</small></p>
|
| 29 |
+
</div>
|
| 30 |
+
</body>
|
| 31 |
+
</html>
|
| 32 |
+
`);
|
| 33 |
+
});
|
| 34 |
+
|
| 35 |
+
app.get('/ping', (req, res) => {
|
| 36 |
+
console.log('Ping reçu à:', new Date().toISOString());
|
| 37 |
+
res.status(200).send('pong');
|
| 38 |
+
});
|
| 39 |
+
|
| 40 |
+
app.listen(PORT, () => {
|
| 41 |
+
console.log(`Serveur démarré sur le port ${PORT}`);
|
| 42 |
+
|
| 43 |
+
// Mécanisme de Keep-Alive interne (Auto-ping toutes les 5 minutes)
|
| 44 |
+
if (SPACE_URL) {
|
| 45 |
+
setInterval(async () => {
|
| 46 |
+
try {
|
| 47 |
+
console.log(`Auto-ping vers ${SPACE_URL}/ping...`);
|
| 48 |
+
await axios.get(`${SPACE_URL}/ping`);
|
| 49 |
+
} catch (error) {
|
| 50 |
+
console.error('Erreur lors de l\'auto-ping:', error.message);
|
| 51 |
+
}
|
| 52 |
+
}, 300000); // 5 minutes
|
| 53 |
+
} else {
|
| 54 |
+
console.log("SPACE_URL non définie. L'auto-ping interne est désactivé.");
|
| 55 |
+
}
|
| 56 |
+
});
|