File size: 888 Bytes
0acb3d3
 
247dfc2
 
0acb3d3
 
247dfc2
 
 
 
 
0acb3d3
247dfc2
0acb3d3
247dfc2
 
 
 
 
 
 
 
 
0acb3d3
 
 
 
 
 
 
 
247dfc2
 
0acb3d3
247dfc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 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);
});