35 lines
605 B
TypeScript
35 lines
605 B
TypeScript
import { Hono } from "hono";
|
|
import { upgradeWebSocket, websocket } from "hono/bun";
|
|
|
|
const app = new Hono();
|
|
|
|
app.get("/", async (c) => {
|
|
return c.json({
|
|
message: "ok",
|
|
});
|
|
});
|
|
|
|
app.get(
|
|
"/ws",
|
|
upgradeWebSocket((c) => {
|
|
return {
|
|
onOpen(event, ws) {
|
|
console.log("Server: Connection opened");
|
|
ws.send("Hello!");
|
|
},
|
|
onClose: () => {
|
|
console.log("Server: Connection closed");
|
|
},
|
|
onMessage: (ev) => {
|
|
console.log(ev.data);
|
|
},
|
|
};
|
|
}),
|
|
);
|
|
|
|
export default {
|
|
port: Bun.env.SERVER_PORT,
|
|
fetch: app.fetch,
|
|
websocket,
|
|
};
|