Stabilize dashboard runtime proxy
This commit is contained in:
@@ -1,35 +1,9 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
const OPENCLAW_LOCAL_DASHBOARD = 'http://127.0.0.1:18789/'
|
||||
import { proxyErrorResponse, proxyOpenClawDashboard } from './shared'
|
||||
|
||||
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'
|
||||
}
|
||||
})
|
||||
return await proxyOpenClawDashboard(request)
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
ok: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to proxy OpenClaw dashboard'
|
||||
}, { status: 500 })
|
||||
return proxyErrorResponse(error)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user