openclaw-navigator 5.4.0 → 5.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +24 -22
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* openclaw-navigator v5.4.
|
|
4
|
+
* openclaw-navigator v5.4.2
|
|
5
5
|
*
|
|
6
6
|
* One-command bridge + tunnel for the Navigator browser.
|
|
7
7
|
* Starts a local bridge, creates a Cloudflare tunnel automatically,
|
|
@@ -981,9 +981,11 @@ function handleRequest(req, res) {
|
|
|
981
981
|
}
|
|
982
982
|
|
|
983
983
|
// ── Reverse proxy: /ui/* → OC Web UI (localhost:ocUIPort) ──────────────
|
|
984
|
-
//
|
|
984
|
+
// Strip /ui prefix — the Next.js app serves at root on port 4000.
|
|
985
|
+
// /ui/ → /, /ui/dashboard → /dashboard, /ui/_next/* → /_next/*
|
|
985
986
|
if (path === "/ui" || path.startsWith("/ui/")) {
|
|
986
|
-
const
|
|
987
|
+
const strippedPath = path === "/ui" ? "/" : path.slice(3); // remove "/ui"
|
|
988
|
+
const targetURL = `${strippedPath}${url.search}`;
|
|
987
989
|
const incomingHost = req.headers.host || "localhost";
|
|
988
990
|
|
|
989
991
|
const proxyOpts = {
|
|
@@ -1009,11 +1011,20 @@ function handleRequest(req, res) {
|
|
|
1009
1011
|
headers["access-control-allow-headers"] = "Content-Type, Authorization, Cookie";
|
|
1010
1012
|
headers["access-control-allow-credentials"] = "true";
|
|
1011
1013
|
|
|
1012
|
-
// Fix redirects — rewrite Location
|
|
1014
|
+
// Fix redirects — rewrite Location: strip localhost, add /ui prefix back
|
|
1015
|
+
// Since we stripped /ui before proxying, any redirect from the app
|
|
1016
|
+
// (e.g. /login, /dashboard) needs the /ui prefix added back for the
|
|
1017
|
+
// browser to stay within our /ui/* proxy.
|
|
1013
1018
|
if (headers.location) {
|
|
1014
|
-
|
|
1019
|
+
let loc = headers.location
|
|
1015
1020
|
.replace(`http://127.0.0.1:${ocUIPort}`, "")
|
|
1016
1021
|
.replace(`http://localhost:${ocUIPort}`, "");
|
|
1022
|
+
// If the redirect is a relative path (starts with /), add /ui prefix
|
|
1023
|
+
// BUT don't double-prefix if it already starts with /ui
|
|
1024
|
+
if (loc.startsWith("/") && !loc.startsWith("/ui")) {
|
|
1025
|
+
loc = "/ui" + loc;
|
|
1026
|
+
}
|
|
1027
|
+
headers.location = loc;
|
|
1017
1028
|
}
|
|
1018
1029
|
|
|
1019
1030
|
// Fix cookies — remove domain restriction so they work through tunnel
|
|
@@ -1105,12 +1116,13 @@ function handleRequest(req, res) {
|
|
|
1105
1116
|
return;
|
|
1106
1117
|
}
|
|
1107
1118
|
|
|
1108
|
-
// ── Reverse proxy: /api
|
|
1109
|
-
//
|
|
1110
|
-
// /api/
|
|
1111
|
-
//
|
|
1112
|
-
//
|
|
1113
|
-
|
|
1119
|
+
// ── Reverse proxy: /api/* → OC Gateway (localhost:ocGatewayPort) ──────────
|
|
1120
|
+
// ALL /api/* requests go to the OC gateway EXCEPT:
|
|
1121
|
+
// - /api/auth/* → falls through to web UI (NextAuth login/session)
|
|
1122
|
+
// - /api/sessions/respond + /api/sessions/stream → handled locally above
|
|
1123
|
+
// The OC web UI frontend expects /api/agents, /api/sessions/*, /api/chat/*,
|
|
1124
|
+
// etc. to reach the gateway. Only /api/auth/* is a Next.js API route.
|
|
1125
|
+
if (path.startsWith("/api/") && !path.startsWith("/api/auth/") && path !== "/api/auth") {
|
|
1114
1126
|
const targetURL = `${path}${url.search}`;
|
|
1115
1127
|
|
|
1116
1128
|
const proxyOpts = {
|
|
@@ -1153,7 +1165,7 @@ function handleRequest(req, res) {
|
|
|
1153
1165
|
if (req.method === "GET" && path === "") {
|
|
1154
1166
|
// Quick probe to check if OC UI is running
|
|
1155
1167
|
const probe = httpRequest(
|
|
1156
|
-
{ hostname: "127.0.0.1", port: ocUIPort, path: "/
|
|
1168
|
+
{ hostname: "127.0.0.1", port: ocUIPort, path: "/", method: "HEAD", timeout: 1000 },
|
|
1157
1169
|
(probeRes) => {
|
|
1158
1170
|
probeRes.resume(); // drain
|
|
1159
1171
|
// OC UI is running — redirect to /ui/
|
|
@@ -1233,16 +1245,6 @@ function handleRequest(req, res) {
|
|
|
1233
1245
|
);
|
|
1234
1246
|
}
|
|
1235
1247
|
|
|
1236
|
-
// If the web UI returns 404 for a GET request, redirect to /ui/ instead
|
|
1237
|
-
// of showing a broken page. This catches post-login redirects to paths
|
|
1238
|
-
// the Next.js app doesn't serve (e.g. / instead of /ui/).
|
|
1239
|
-
if (proxyRes.statusCode === 404 && req.method === "GET") {
|
|
1240
|
-
proxyRes.resume(); // drain the 404 body
|
|
1241
|
-
res.writeHead(302, { ...headers, Location: "/ui/" });
|
|
1242
|
-
res.end();
|
|
1243
|
-
return;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
1248
|
res.writeHead(proxyRes.statusCode ?? 502, headers);
|
|
1247
1249
|
proxyRes.pipe(res, { end: true });
|
|
1248
1250
|
});
|