47 lines
921 B
TypeScript
47 lines
921 B
TypeScript
import { Hono } from "hono";
|
|
import { upgradeWebSocket, websocket } from "hono/bun";
|
|
import { DatabaseService } from "@/services/database-service";
|
|
|
|
const app = new Hono();
|
|
|
|
app.get("/", async (c) => {
|
|
const database = new DatabaseService();
|
|
await database.getClient().user.create({
|
|
data: {
|
|
email: "rosati5.matteo@gmail.com",
|
|
name: "Matteo",
|
|
},
|
|
});
|
|
|
|
const users = await database.getClient().user.findMany();
|
|
|
|
return c.json({
|
|
message: "ok",
|
|
users: users,
|
|
});
|
|
});
|
|
|
|
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,
|
|
};
|