web_surf_API / server_forTest.js
simoncck's picture
Rename server.js to server_forTest.js
87cedbd verified
raw
history blame contribute delete
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);
});