Rename app.mjs to app.ts
Browse files
app.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
| 1 |
-
import { Hono } from 'hono';
|
| 2 |
-
|
| 3 |
-
const app = new Hono();
|
| 4 |
-
let rooms = {};
|
| 5 |
-
|
| 6 |
-
app.post('/join', async c => {
|
| 7 |
-
const { roomId, peerId } = await c.req.json();
|
| 8 |
-
if (!rooms[roomId]) rooms[roomId] = [];
|
| 9 |
-
if (!rooms[roomId].includes(peerId)) rooms[roomId].push(peerId);
|
| 10 |
-
|
| 11 |
-
return c.json({ peers: rooms[roomId].filter(p => p !== peerId) });
|
| 12 |
-
});
|
| 13 |
-
|
| 14 |
-
app.fire();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Hono } from "hono";
|
| 2 |
+
import { serve } from "@hono/node-server";
|
| 3 |
+
|
| 4 |
+
const app = new Hono();
|
| 5 |
+
|
| 6 |
+
let rooms: Record<string, string[]> = {};
|
| 7 |
+
|
| 8 |
+
app.post("/join", async (c) => {
|
| 9 |
+
const { roomId, peerId } = await c.req.json();
|
| 10 |
+
|
| 11 |
+
if (!rooms[roomId]) {
|
| 12 |
+
rooms[roomId] = [];
|
| 13 |
+
}
|
| 14 |
+
if (!rooms[roomId].includes(peerId)) {
|
| 15 |
+
rooms[roomId].push(peerId);
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
return c.json({
|
| 19 |
+
peers: rooms[roomId].filter((p) => p !== peerId),
|
| 20 |
+
});
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
// 🚀 start server
|
| 24 |
+
serve(app, (info) => {
|
| 25 |
+
console.log(`✅ Server is running at http://localhost:${info.port}`);
|
| 26 |
+
});
|