share pids, proxy api

This commit is contained in:
Chris Wanstrath 2026-02-04 08:54:35 -08:00
parent 913f8f34d7
commit 0d572b4b5d
3 changed files with 32 additions and 4 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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[]