1- import { registry } from "./registry" ;
2- import { auth } from "./auth" ;
3- import { Hono } from "hono" ;
4- import { serve } from "@hono/node-server" ;
5- import { createMemoryDriver } from "@rivetkit/memory" ;
6-
7- // Setup router
8- const app = new Hono ( ) ;
9-
10- // Start RivetKit
11- const { client, hono } = registry . run ( {
12- driver : createMemoryDriver ( ) ,
13- cors : {
14- // IMPORTANT: Configure origins in production
15- origin : "*" ,
16- } ,
17- } ) ;
18-
19- // Mount Better Auth routes
20- app . on ( [ "GET" , "POST" ] , "/api/auth/**" , ( c ) => auth . handler ( c . req . raw ) ) ;
21-
22- // Expose RivetKit to the frontend
23- app . route ( "/registry" , hono ) ;
24-
25- // Example HTTP endpoint to join chat room
26- app . post ( "/api/join-room/:roomId" , async ( c ) => {
27- const roomId = c . req . param ( "roomId" ) ;
28-
29- // Verify authentication
30- const authResult = await auth . api . getSession ( {
31- headers : c . req . header ( ) ,
32- } ) ;
33-
34- if ( ! authResult ?. session || ! authResult ?. user ) {
35- return c . json ( { error : "Unauthorized" } , 401 ) ;
36- }
37-
38- try {
39- const room = client . chatRoom . getOrCreate ( roomId ) ;
40- const messages = await room . getMessages ( ) ;
41-
42- return c . json ( {
43- success : true ,
44- roomId,
45- messages,
46- user : authResult . user
47- } ) ;
48- } catch ( error ) {
49- return c . json ( { error : "Failed to join room" } , 500 ) ;
50- }
51- } ) ;
52-
53- serve ( { fetch : app . fetch , port : 6420 } , ( ) =>
54- console . log ( "Listening at http://localhost:6420" ) ,
55- ) ;
1+ // import { registry } from "./registry";
2+ // import { auth } from "./auth";
3+ // import { Hono } from "hono";
4+ // import { serve } from "@hono/node-server";
5+ //
6+ // // Setup router
7+ // const app = new Hono();
8+ //
9+ // // Start RivetKit
10+ // const { client, hono } = registry.run({
11+ // driver: createMemoryDriver(),
12+ // cors: {
13+ // // IMPORTANT: Configure origins in production
14+ // origin: "*",
15+ // },
16+ // });
17+ //
18+ // // Mount Better Auth routes
19+ // app.on(["GET", "POST"], "/api/auth/**", (c) => auth.handler(c.req.raw));
20+ //
21+ // // Expose RivetKit to the frontend
22+ // app.route("/registry", hono);
23+ //
24+ // // Example HTTP endpoint to join chat room
25+ // app.post("/api/join-room/:roomId", async (c) => {
26+ // const roomId = c.req.param("roomId");
27+ //
28+ // // Verify authentication
29+ // const authResult = await auth.api.getSession({
30+ // headers: c.req.header(),
31+ // });
32+ //
33+ // if (!authResult?.session || !authResult?.user) {
34+ // return c.json({ error: "Unauthorized" }, 401);
35+ // }
36+ //
37+ // try {
38+ // const room = client.chatRoom.getOrCreate(roomId);
39+ // const messages = await room.getMessages();
40+ //
41+ // return c.json({
42+ // success: true,
43+ // roomId,
44+ // messages,
45+ // user: authResult.user
46+ // });
47+ // } catch (error) {
48+ // return c.json({ error: "Failed to join room" }, 500);
49+ // }
50+ // });
51+ //
52+ // serve({ fetch: app.fetch, port: 6420 }, () =>
53+ // console.log("Listening at http://localhost:6420"),
54+ // );
0 commit comments