Update server.js
Browse files
server.js
CHANGED
|
@@ -1,52 +1,33 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 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.
|
| 21 |
-
});
|
| 22 |
-
|
| 23 |
-
app.get("/health", (_, res) => {
|
| 24 |
-
res.json({ status: "ok" });
|
| 25 |
});
|
| 26 |
|
| 27 |
app.post("/run", (req, res) => {
|
| 28 |
-
const
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
stdout,
|
| 45 |
-
stderr
|
| 46 |
-
});
|
| 47 |
});
|
| 48 |
});
|
| 49 |
|
| 50 |
-
app.listen(
|
| 51 |
-
console.log(
|
| 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 |
});
|