Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/raw-websocket-handler-proxy/src/backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { createNodeWebSocket } from "@hono/node-ws";
import { Hono } from "hono";
import { registry } from "./registry.js";

const { client } = registry.createServer();
const { client, hono } = registry.createServer({
getUpgradeWebSocket: () => upgradeWebSocket,
});

const app = new Hono();
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
Comment on lines +6 to 11
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be a circular dependency in this code. The upgradeWebSocket function is being passed to registry.createServer() before it's actually defined on line 11.

To resolve this issue, please move the registry creation code:

const { client, hono } = registry.createServer({
  getUpgradeWebSocket: () => upgradeWebSocket,
});

to after line 11 where upgradeWebSocket is defined. This will ensure the function exists before it's referenced.

Suggested change
const { client, hono } = registry.createServer({
getUpgradeWebSocket: () => upgradeWebSocket,
});
const app = new Hono();
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
const app = new Hono();
const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
const { client, hono } = registry.createServer({
getUpgradeWebSocket: () => upgradeWebSocket,
});

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

Expand Down Expand Up @@ -45,5 +47,8 @@ app.get(
}),
);

// Mount RivetKit's registry (optional, but required for Studio integration)
app.route("/registry", hono);

const server = serve({ port: 8080, fetch: app.fetch });
injectWebSocket(server);
2 changes: 1 addition & 1 deletion examples/raw-websocket-handler-proxy/src/frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function App() {
`conn_params.${encodeURIComponent(JSON.stringify({ apiKey: "your-api-key" }))}`
];

const ws = new WebSocket("ws://localhost:8080/registry/actors/chatRoom/ws/", protocols);
const ws = new WebSocket("ws://localhost:8080/registry/actors/raw/websocket/", protocols);

ws.onopen = () => {
setIsConnected(true);
Expand Down
1 change: 0 additions & 1 deletion examples/raw-websocket-handler-proxy/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe("basic websocket test", () => {

expect(initMessage.type).toBe("init");
expect(initMessage.messages).toEqual([]);
expect(initMessage.users).toBeDefined();

// Send a message
ws.send(JSON.stringify({ type: "message", text: "Hello!" }));
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/test/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { type TestContext, vi } from "vitest";
import { type Client, createClient } from "@/client/mod";
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
import { createInlineClientDriver } from "@/inline-client-driver/mod";
import { getStudioUrl } from "@/inspector/utils";
import { createManagerRouter } from "@/manager/router";
import type { Registry } from "@/registry/mod";
import { RunConfigSchema } from "@/registry/run-config";
import { ConfigSchema, type InputConfig } from "./config";
import { logger } from "./log";

Expand All @@ -27,12 +25,11 @@ function serve(registry: Registry<any>, inputConfig?: InputConfig): ServerType {
}

// Create router
const runConfig = RunConfigSchema.parse(inputConfig);
const managerDriver = config.driver.manager(registry.config, config);
const inlineClientDriver = createInlineClientDriver(managerDriver);
const { router } = createManagerRouter(
registry.config,
runConfig,
config,
inlineClientDriver,
managerDriver,
);
Expand Down
Loading