Spaces:
Sleeping
Sleeping
| // server.js (minimal + echo) | |
| import express from 'express'; | |
| const PORT = process.env.PORT || 7860; | |
| const SPACE_ID = process.env.SPACE_ID || ''; | |
| const HOSTNAME = SPACE_ID | |
| ? `https://${SPACE_ID.replace(/\//g, '-').replace(/_/g, '-')}.hf.space` | |
| : '(local run)'; | |
| const app = express(); | |
| app.use(express.json()); // β parse JSON bodies | |
| /* GET / : sanity ping */ | |
| app.get('/', (req, res) => { | |
| res.json({ | |
| ok: true, | |
| hostSeenByServer: req.headers.host, | |
| youHit: req.originalUrl, | |
| spaceId: SPACE_ID || null, | |
| }); | |
| }); | |
| /* POST /echo : return whatever JSON you sent */ | |
| app.post('/echo', (req, res) => { | |
| res.json({ | |
| received_at: new Date().toISOString(), | |
| body: req.body | |
| }); | |
| }); | |
| app.listen(PORT, '0.0.0.0', () => { | |
| console.log('π°οΈ Public URL should be:', HOSTNAME); | |
| console.log('π Echo test server listening on', PORT); | |
| }); | |