index.ts 987 B

1234567891011121314151617181920212223242526272829
  1. /** Host HTTP bridge for browser-client RPC. */
  2. import type { Context } from 'cordis'
  3. // Activates the httpServer Context merge used below.
  4. import type { WebRoute } from '@deepseek-ai/dsh-host-webserver'
  5. import { toFetchHandler } from '@deepseek-ai/dsh-host-apiproxy'
  6. import { API_PATH } from './api-path.ts'
  7. import { bridge } from './http-bridge.ts'
  8. export { API_PATH } from './api-path.ts'
  9. /** Stable Cordis plugin name. */
  10. export const name = 'client-connection'
  11. /** Services required before mounting the route. */
  12. export const inject = ['httpServer', 'apiProxy']
  13. /**
  14. * Mounts the API gateway under the browser transport prefix.
  15. * @param ctx - Host plugin context.
  16. */
  17. export function apply(ctx: Context): void {
  18. const apiHandler = toFetchHandler(ctx.apiProxy)
  19. const route: WebRoute = {
  20. kind: 'prefix',
  21. path: API_PATH,
  22. handler: (req, res) => bridge(req, res, apiHandler),
  23. }
  24. ctx.effect(() => ctx.httpServer.register(route), 'client-connection: /api route')
  25. }