Skip to content
Closed
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
13 changes: 2 additions & 11 deletions examples/next-js/src/lib/rivet-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
import { createClient, createRivetKit } from "@rivetkit/next-js/client";
import type { registry } from "@/rivet/registry";

const getOrigin = () => {
if (typeof window !== "undefined") {
return window.location.origin;
}
// Fallback for SSR or when window is not available
return process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
};
// TODO: Auto-trigger start by sending request to health endpoint

const client = createClient<typeof registry>({
endpoint: `${getOrigin()}/api/rivet`,
transport: "sse",
});
const client = createClient<typeof registry>();
export const { useActor } = createRivetKit(client);
15 changes: 14 additions & 1 deletion packages/next-js/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,20 @@ export const toNextHandler = (
) => {
// Don't run server locally since we're using the fetch handler directly
inputConfig.disableDefaultServer = true;
inputConfig.disableActorDriver = true;

// Configure serverless
const publicUrl =
process.env.NEXT_PUBLIC_SITE_URL ??
process.env.NEXT_PUBLIC_VERCEL_URL ??
`http://127.0.0.1:${process.env.PORT ?? 8080}`;
inputConfig.runnerKind = "serverless";
inputConfig.runEngine = true;
inputConfig.autoConfigureServerless = {
url: `${publicUrl}/api/rivet/start`,
};

// Next logs this on every request
inputConfig.noWelcome = true;

const { fetch } = registry.start(inputConfig);

Expand Down
3 changes: 2 additions & 1 deletion packages/rivetkit/src/manager/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ async function handleHttpGateway(
headers: proxyHeaders,
body: c.req.raw.body,
signal: c.req.raw.signal,
});
duplex: "half",
} as RequestInit);

return await managerDriver.proxyRequest(c, proxyRequest, actorId);
}
Expand Down
Loading