From 4de15bc8abcdf96cb5fc2c3f82f76e75fcf85fc3 Mon Sep 17 00:00:00 2001 From: Mark McKeen Date: Sun, 29 Mar 2026 09:59:15 -0600 Subject: [PATCH] feat: proxy loopback-only OpenClaw dashboard through web UI - add dashboard proxy route for local OpenClaw endpoint - return proxiedUrl from dashboard open API - update sandbox button to open proxied route in new tab --- app/api/openshell/dashboard/open/route.ts | 3 +- app/api/openshell/dashboard/proxy/route.ts | 35 ++++++++++++++++++++++ app/components/SandboxList.tsx | 6 ++-- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/api/openshell/dashboard/proxy/route.ts diff --git a/app/api/openshell/dashboard/open/route.ts b/app/api/openshell/dashboard/open/route.ts index fd41fd9..afb478f 100644 --- a/app/api/openshell/dashboard/open/route.ts +++ b/app/api/openshell/dashboard/open/route.ts @@ -6,8 +6,9 @@ export async function GET() { return NextResponse.json({ ok: true, dashboardUrl, + proxiedUrl: '/api/openshell/dashboard/proxy', openInNewTab: true, loopbackOnly: true, - note: 'OpenClaw Dashboard is loopback-only on the host. For remote browser access, add a reverse proxy route or rebind the gateway.' + note: 'OpenClaw Dashboard is loopback-only on the host, so the web UI uses a local proxy route to expose it.' }) } diff --git a/app/api/openshell/dashboard/proxy/route.ts b/app/api/openshell/dashboard/proxy/route.ts new file mode 100644 index 0000000..8a18b95 --- /dev/null +++ b/app/api/openshell/dashboard/proxy/route.ts @@ -0,0 +1,35 @@ +import { NextResponse } from 'next/server' + +const OPENCLAW_LOCAL_DASHBOARD = 'http://127.0.0.1:18789/' + +export async function GET(request: Request) { + try { + const url = new URL(request.url) + const targetPath = url.searchParams.get('path') || '' + const target = new URL(targetPath, OPENCLAW_LOCAL_DASHBOARD) + + const upstream = await fetch(target.toString(), { + method: 'GET', + headers: { + accept: 'text/html,application/json;q=0.9,*/*;q=0.8' + }, + cache: 'no-store' + }) + + const contentType = upstream.headers.get('content-type') || 'text/html; charset=utf-8' + const body = await upstream.text() + + return new NextResponse(body, { + status: upstream.status, + headers: { + 'content-type': contentType, + 'cache-control': 'no-store' + } + }) + } catch (error) { + return NextResponse.json({ + ok: false, + error: error instanceof Error ? error.message : 'Failed to proxy OpenClaw dashboard' + }, { status: 500 }) + } +} diff --git a/app/components/SandboxList.tsx b/app/components/SandboxList.tsx index 7e9ce02..85a1319 100644 --- a/app/components/SandboxList.tsx +++ b/app/components/SandboxList.tsx @@ -181,9 +181,11 @@ export default function SandboxList({ const res = await fetch('/api/openshell/dashboard/open') const data = await res.json() setDashboardMessage(data.loopbackOnly - ? `OpenClaw Dashboard detected at ${data.dashboardUrl}. It is loopback-only, so the next step is adding a proxy/open-in-new-tab bridge.` + ? `OpenClaw Dashboard detected at ${data.dashboardUrl}. Opening proxied dashboard route.` : `OpenClaw Dashboard: ${data.dashboardUrl}`) - if (data.dashboardUrl && !data.loopbackOnly) { + if (data.proxiedUrl) { + window.open(data.proxiedUrl, '_blank', 'noopener,noreferrer') + } else if (data.dashboardUrl && !data.loopbackOnly) { window.open(data.dashboardUrl, '_blank', 'noopener,noreferrer') } } catch (error) {