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

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +21 -40
server.js CHANGED
@@ -1,52 +1,33 @@
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
- });
34
-
35
- let stdout = "";
36
- let stderr = "";
37
-
38
- child.stdout.on("data", d => (stdout += d.toString()));
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
  });
 
1
+ import express from "express";
2
+ import { spawn } from "child_process";
 
3
 
4
  const app = express();
5
  app.use(express.json());
6
 
 
 
 
 
 
 
 
 
 
 
 
7
  app.get("/", (_, res) => {
8
+ res.json({ status: "OpenClaw Space running" });
 
 
 
 
9
  });
10
 
11
  app.post("/run", (req, res) => {
12
+ const proc = spawn(
13
+ "node",
14
+ ["src/index.js"],
15
+ {
16
+ cwd: "/app/openclaw",
17
+ env: process.env
18
+ }
19
+ );
20
+
21
+ let output = "";
22
+
23
+ proc.stdout.on("data", d => output += d.toString());
24
+ proc.stderr.on("data", d => output += d.toString());
25
+
26
+ proc.on("close", code => {
27
+ res.json({ exitCode: code, output });
 
 
 
28
  });
29
  });
30
 
31
+ app.listen(7860, () => {
32
+ console.log("🚀 OpenClaw wrapper listening on 7860");
33
  });