[verified] refactor: establish service and frontend boundaries

This commit is contained in:
chick
2026-07-15 02:43:41 +08:00
parent 0ac6faa6a3
commit e04a16e817
29 changed files with 917 additions and 598 deletions
+14
View File
@@ -0,0 +1,14 @@
import { proxyToInstance } from './service.js'
export function registerProxyRoutes(app, { findClient, proxy = proxyToInstance }) {
app.all('/api/proxy/:id/*', async (request, reply) => {
const client = findClient(request.params.id, reply)
if (!client) return
try { return await proxy({ client, request, reply, rest: request.params['*'] }) }
catch (error) {
if (/invalid proxy path/.test(error.message)) return reply.code(400).send({ error: error.message })
if (error.statusCode === 415) return reply.code(415).send({ error: error.message })
throw error
}
})
}