share pids, proxy api
This commit is contained in:
parent
913f8f34d7
commit
0d572b4b5d
|
|
@ -16,10 +16,8 @@ const router = Hype.router()
|
||||||
|
|
||||||
// BackendApp -> SharedApp
|
// BackendApp -> SharedApp
|
||||||
function convert(app: BackendApp): SharedApp {
|
function convert(app: BackendApp): SharedApp {
|
||||||
const clone = { ...app }
|
const { proc, logs, ...rest } = app
|
||||||
delete clone.proc
|
return { ...rest, pid: proc?.pid }
|
||||||
delete clone.logs
|
|
||||||
return clone
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSE endpoint for real-time app state updates
|
// SSE endpoint for real-time app state updates
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,35 @@ app.get('/tool/:tool', c => {
|
||||||
return c.redirect(url)
|
return c.redirect(url)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Tool API proxy: /api/tools/:tool/* -> proxy to tool port
|
||||||
|
app.all('/api/tools/:tool/:path{.+}', async c => {
|
||||||
|
const toolName = c.req.param('tool')
|
||||||
|
const tool = allApps().find(a => a.tool && a.name === toolName)
|
||||||
|
if (!tool || tool.state !== 'running' || !tool.port) {
|
||||||
|
return c.json({ error: `Tool "${toolName}" not found or not running` }, 404)
|
||||||
|
}
|
||||||
|
|
||||||
|
const subPath = '/' + c.req.param('path')
|
||||||
|
|
||||||
|
// Build target URL
|
||||||
|
const params = new URLSearchParams(c.req.query()).toString()
|
||||||
|
const targetUrl = params
|
||||||
|
? `http://localhost:${tool.port}${subPath}?${params}`
|
||||||
|
: `http://localhost:${tool.port}${subPath}`
|
||||||
|
|
||||||
|
// Proxy the request
|
||||||
|
const response = await fetch(targetUrl, {
|
||||||
|
method: c.req.method,
|
||||||
|
headers: c.req.raw.headers,
|
||||||
|
body: c.req.method !== 'GET' && c.req.method !== 'HEAD' ? c.req.raw.body : undefined,
|
||||||
|
})
|
||||||
|
|
||||||
|
return new Response(response.body, {
|
||||||
|
status: response.status,
|
||||||
|
headers: response.headers,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
initApps()
|
initApps()
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ export type App = {
|
||||||
state: AppState
|
state: AppState
|
||||||
icon: string
|
icon: string
|
||||||
error?: string
|
error?: string
|
||||||
|
pid?: number
|
||||||
port?: number
|
port?: number
|
||||||
started?: number
|
started?: number
|
||||||
logs?: LogLine[]
|
logs?: LogLine[]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user