|
1 | 1 | import { Hono } from "hono"; |
2 | 2 | import { cors } from "hono/cors"; |
3 | 3 | import { initActorRuntimeContext } from "./actors/context.js"; |
4 | | -import { registry, resolveManagerPort } from "./actors/index.js"; |
| 4 | +import { registry } from "./actors/index.js"; |
5 | 5 | import { workspaceKey } from "./actors/keys.js"; |
6 | 6 | import { loadConfig } from "./config/backend.js"; |
7 | 7 | import { createBackends, createNotificationService } from "./notifications/index.js"; |
@@ -69,17 +69,11 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v |
69 | 69 | const notifications = createNotificationService(backends); |
70 | 70 | initActorRuntimeContext(config, providers, notifications, driver, createDefaultAppShellServices()); |
71 | 71 |
|
72 | | - registry.startRunner(); |
73 | | - const managerOrigin = `http://127.0.0.1:${resolveManagerPort()}`; |
74 | 72 | const actorClient = createClient({ |
75 | | - endpoint: managerOrigin, |
76 | | - disableMetadataLookup: true, |
| 73 | + endpoint: `http://127.0.0.1:${config.backend.port}/api/rivet`, |
77 | 74 | }) as any; |
78 | 75 |
|
79 | | - // Wrap in a Hono app mounted at /api/rivet to serve on the backend port. |
80 | | - // Uses Bun.serve — cannot use @hono/node-server because it conflicts with |
81 | | - // RivetKit's internal Bun.serve manager server (Bun bug: mixing Node HTTP |
82 | | - // server and Bun.serve in the same process breaks Bun.serve's fetch handler). |
| 76 | + // Wrap RivetKit and app routes in a single Hono app mounted at /api/rivet. |
83 | 77 | const app = new Hono(); |
84 | 78 | const allowHeaders = [ |
85 | 79 | "Content-Type", |
@@ -118,21 +112,6 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v |
118 | 112 | exposeHeaders, |
119 | 113 | }), |
120 | 114 | ); |
121 | | - const forward = async (c: any) => { |
122 | | - try { |
123 | | - // Proxy /api/rivet traffic to the long-lived RivetKit manager rather than |
124 | | - // invoking RivetKit's serverless entrypoints in-process. |
125 | | - const requestUrl = new URL(c.req.url); |
126 | | - const managerPath = requestUrl.pathname.replace(/^\/api\/rivet(?=\/|$)/, "") || "/"; |
127 | | - const targetUrl = new URL(`${managerPath}${requestUrl.search}`, managerOrigin); |
128 | | - return await fetch(new Request(targetUrl, c.req.raw)); |
129 | | - } catch (err) { |
130 | | - if (err instanceof URIError) { |
131 | | - return c.text("Bad Request: Malformed URI", 400); |
132 | | - } |
133 | | - throw err; |
134 | | - } |
135 | | - }; |
136 | 115 |
|
137 | 116 | const appWorkspace = async () => |
138 | 117 | await withRetries( |
@@ -334,8 +313,18 @@ export async function startBackend(options: BackendStartOptions = {}): Promise<v |
334 | 313 | app.post("/api/rivet/app/webhooks/stripe", handleStripeWebhook); |
335 | 314 | app.post("/api/rivet/app/stripe/webhook", handleStripeWebhook); |
336 | 315 |
|
337 | | - app.all("/api/rivet", forward); |
338 | | - app.all("/api/rivet/*", forward); |
| 316 | + app.post("/api/rivet/app/webhooks/github", async (c) => { |
| 317 | + const payload = await c.req.text(); |
| 318 | + await (await appWorkspace()).handleAppGithubWebhook({ |
| 319 | + payload, |
| 320 | + signatureHeader: c.req.header("x-hub-signature-256") ?? null, |
| 321 | + eventHeader: c.req.header("x-github-event") ?? null, |
| 322 | + }); |
| 323 | + return c.json({ ok: true }); |
| 324 | + }); |
| 325 | + |
| 326 | + app.all("/api/rivet", (c) => registry.handler(c.req.raw)); |
| 327 | + app.all("/api/rivet/*", (c) => registry.handler(c.req.raw)); |
339 | 328 |
|
340 | 329 | const server = Bun.serve({ |
341 | 330 | fetch: app.fetch, |
|
0 commit comments