getzero11 commited on
Commit
e2146c6
·
verified ·
1 Parent(s): e85ed05

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +17 -30
server.js CHANGED
@@ -1,50 +1,33 @@
1
  const express = require("express");
2
  const { spawn } = require("child_process");
3
  const path = require("path");
4
- const fs = require("fs");
5
 
6
  const app = express();
7
  app.use(express.json());
8
 
9
  const PORT = process.env.PORT || 7860;
10
 
 
 
 
 
 
 
 
 
 
11
  app.get("/", (_, res) => {
12
- res.send("✅ Moltbot is running on Hugging Face Space");
13
  });
14
 
15
  app.get("/health", (_, res) => {
16
  res.json({ status: "ok" });
17
  });
18
 
19
- function findMoltbotEntry() {
20
- const base = path.join(process.cwd(), "node_modules", "moltbot");
21
-
22
- const candidates = [
23
- "dist/index.js",
24
- "dist/cli.js",
25
- "src/index.js",
26
- "index.js"
27
- ];
28
-
29
- for (const rel of candidates) {
30
- const full = path.join(base, rel);
31
- if (fs.existsSync(full)) return full;
32
- }
33
-
34
- throw new Error("Could not locate Moltbot entry file");
35
- }
36
-
37
  app.post("/run", (req, res) => {
38
- let entry;
39
- try {
40
- entry = findMoltbotEntry();
41
- } catch (e) {
42
- return res.status(500).json({ error: e.message });
43
- }
44
-
45
  const args = Array.isArray(req.body?.args) ? req.body.args : [];
46
 
47
- const child = spawn("node", [entry, ...args], {
48
  env: process.env,
49
  cwd: process.cwd()
50
  });
@@ -56,10 +39,14 @@ app.post("/run", (req, res) => {
56
  child.stderr.on("data", d => (stderr += d.toString()));
57
 
58
  child.on("close", code => {
59
- res.json({ exitCode: code, stdout, stderr });
 
 
 
 
60
  });
61
  });
62
 
63
  app.listen(PORT, "0.0.0.0", () => {
64
- console.log(`🚀 Moltbot listening on port ${PORT}`);
65
  });
 
1
  const express = require("express");
2
  const { spawn } = require("child_process");
3
  const path = require("path");
 
4
 
5
  const app = express();
6
  app.use(express.json());
7
 
8
  const PORT = process.env.PORT || 7860;
9
 
10
+ // OpenClaw CLI entry
11
+ const OPENCLAW_ENTRY = path.join(
12
+ process.cwd(),
13
+ "node_modules",
14
+ "openclaw",
15
+ "src",
16
+ "index.js"
17
+ );
18
+
19
  app.get("/", (_, res) => {
20
+ res.send("✅ OpenClaw (Moltbot) running on HF Space");
21
  });
22
 
23
  app.get("/health", (_, res) => {
24
  res.json({ status: "ok" });
25
  });
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  app.post("/run", (req, res) => {
 
 
 
 
 
 
 
28
  const args = Array.isArray(req.body?.args) ? req.body.args : [];
29
 
30
+ const child = spawn("node", [OPENCLAW_ENTRY, ...args], {
31
  env: process.env,
32
  cwd: process.cwd()
33
  });
 
39
  child.stderr.on("data", d => (stderr += d.toString()));
40
 
41
  child.on("close", code => {
42
+ res.json({
43
+ exitCode: code,
44
+ stdout,
45
+ stderr
46
+ });
47
  });
48
  });
49
 
50
  app.listen(PORT, "0.0.0.0", () => {
51
+ console.log(`🚀 OpenClaw listening on port ${PORT}`);
52
  });