2025-10-22 06:12:25 -04:00
|
|
|
import { Server as Engine } from "@socket.io/bun-engine";
|
|
|
|
|
import { Server } from "socket.io";
|
|
|
|
|
import { Hono } from "hono";
|
|
|
|
|
import { cors } from 'hono/cors';
|
|
|
|
|
import { PrismaClient } from "./generated/prisma";
|
2025-10-22 01:18:32 -04:00
|
|
|
|
2025-10-22 06:12:25 -04:00
|
|
|
const io = new Server();
|
2025-10-22 01:18:32 -04:00
|
|
|
|
2025-10-22 06:12:25 -04:00
|
|
|
const engine = new Engine();
|
|
|
|
|
engine.opts.cors = {
|
|
|
|
|
origin: "*"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
io.bind(engine);
|
|
|
|
|
|
|
|
|
|
io.on("connection", (socket) => {
|
|
|
|
|
console.log("conn")
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const app = new Hono();
|
|
|
|
|
app.use(cors({ origin: '*' }))
|
|
|
|
|
|
|
|
|
|
const { websocket } = engine.handler();
|
|
|
|
|
|
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
|
prisma.user.findMany().then((data) => console.log(data));
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
port: 3000,
|
|
|
|
|
idleTimeout: 30, // must be greater than the "pingInterval" option of the engine, which defaults to 25 seconds
|
|
|
|
|
fetch(req: Request, server: unknown) {
|
|
|
|
|
const url = new URL(req.url);
|
|
|
|
|
|
|
|
|
|
if (url.pathname === "/socket.io/") {
|
|
|
|
|
return engine.handleRequest(req, server);
|
|
|
|
|
} else {
|
|
|
|
|
return app.fetch(req, server);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
websocket
|
|
|
|
|
}
|