Spaces:
Sleeping
Sleeping
Update server.js
Browse files
server.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
| 1 |
-
// server.js
|
|
|
|
| 2 |
import express from 'express';
|
| 3 |
|
| 4 |
-
const PORT = process.env.PORT || 7860;
|
| 5 |
-
const SPACE_ID = process.env.SPACE_ID || '';
|
| 6 |
const HOSTNAME = SPACE_ID
|
| 7 |
? `https://${SPACE_ID.replace(/\//g, '-').replace(/_/g, '-')}.hf.space`
|
| 8 |
: '(local run)';
|
| 9 |
|
| 10 |
const app = express();
|
|
|
|
| 11 |
|
| 12 |
-
/*
|
| 13 |
app.get('/', (req, res) => {
|
| 14 |
res.json({
|
| 15 |
ok: true,
|
|
@@ -19,8 +21,15 @@ app.get('/', (req, res) => {
|
|
| 19 |
});
|
| 20 |
});
|
| 21 |
|
| 22 |
-
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
app.listen(PORT, '0.0.0.0', () => {
|
| 24 |
console.log('🛰️ Public URL should be:', HOSTNAME);
|
| 25 |
-
console.log('🚀
|
| 26 |
});
|
|
|
|
| 1 |
+
// server.js (minimal + echo)
|
| 2 |
+
|
| 3 |
import express from 'express';
|
| 4 |
|
| 5 |
+
const PORT = process.env.PORT || 7860;
|
| 6 |
+
const SPACE_ID = process.env.SPACE_ID || '';
|
| 7 |
const HOSTNAME = SPACE_ID
|
| 8 |
? `https://${SPACE_ID.replace(/\//g, '-').replace(/_/g, '-')}.hf.space`
|
| 9 |
: '(local run)';
|
| 10 |
|
| 11 |
const app = express();
|
| 12 |
+
app.use(express.json()); // ← parse JSON bodies
|
| 13 |
|
| 14 |
+
/* GET / : sanity ping */
|
| 15 |
app.get('/', (req, res) => {
|
| 16 |
res.json({
|
| 17 |
ok: true,
|
|
|
|
| 21 |
});
|
| 22 |
});
|
| 23 |
|
| 24 |
+
/* POST /echo : return whatever JSON you sent */
|
| 25 |
+
app.post('/echo', (req, res) => {
|
| 26 |
+
res.json({
|
| 27 |
+
received_at: new Date().toISOString(),
|
| 28 |
+
body: req.body
|
| 29 |
+
});
|
| 30 |
+
});
|
| 31 |
+
|
| 32 |
app.listen(PORT, '0.0.0.0', () => {
|
| 33 |
console.log('🛰️ Public URL should be:', HOSTNAME);
|
| 34 |
+
console.log('🚀 Echo test server listening on', PORT);
|
| 35 |
});
|