| const express = require('express'); |
| const axios = require('axios'); |
| const app = express(); |
| const PORT = process.env.PORT || 7860; |
|
|
| |
| const SPACE_URL = process.env.SPACE_URL; |
|
|
| app.get('/', (req, res) => { |
| res.send(` |
| <html> |
| <head> |
| <title>Persistent Space Keep-Alive</title> |
| <style> |
| body { font-family: sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: #f0f2f5; } |
| .card { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; } |
| h1 { color: #2d3436; } |
| p { color: #636e72; } |
| .status { font-weight: bold; color: #00b894; } |
| </style> |
| </head> |
| <body> |
| <div class="card"> |
| <h1>Space Persistant Actif</h1> |
| <p>Ce Space est configuré pour rester éveillé.</p> |
| <p>Statut: <span class="status">En ligne 24/7</span></p> |
| <hr> |
| <p><small>Dernier auto-ping: ${new Date().toISOString()}</small></p> |
| </div> |
| </body> |
| </html> |
| `); |
| }); |
|
|
| app.get('/ping', (req, res) => { |
| console.log('Ping reçu à:', new Date().toISOString()); |
| res.status(200).send('pong'); |
| }); |
|
|
| app.listen(PORT, () => { |
| console.log(`Serveur démarré sur le port ${PORT}`); |
| |
| |
| if (SPACE_URL) { |
| setInterval(async () => { |
| try { |
| console.log(`Auto-ping vers ${SPACE_URL}/ping...`); |
| await axios.get(`${SPACE_URL}/ping`); |
| } catch (error) { |
| console.error('Erreur lors de l\'auto-ping:', error.message); |
| } |
| }, 300000); |
| } else { |
| console.log("SPACE_URL non définie. L'auto-ping interne est désactivé."); |
| } |
| }); |
|
|