Spaces:
Sleeping
Sleeping
Download server_forTest.js from simoncck/web_surf_API: direct link, hf CLI and curl.
- Browser
- Download file 888 Bytes
-
https://huggingface.co/spaces/simoncck/web_surf_API/resolve/main/server_forTest.js
- Command line
-
hf download hf://spaces/simoncck/web_surf_API/server_forTest.js
-
curl -L -o server_forTest.js https://huggingface.co/spaces/simoncck/web_surf_API/resolve/main/server_forTest.js
888 Bytes
| // 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); | |
| }); | |