mid dev
This commit is contained in:
@@ -1,6 +1,42 @@
|
||||
import { Hono } from 'hono'
|
||||
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";
|
||||
|
||||
const app = new Hono()
|
||||
app.get('/', (c) => c.text('Hello Bun!'))
|
||||
const io = new Server();
|
||||
|
||||
export default app
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user