feat: Next.js + Socket.IO 3-mode game (Skribbl, Gartic, Color)

This commit is contained in:
PM
2026-05-01 20:12:36 +00:00
parent b02976c10b
commit 2a40097fad
47 changed files with 7907 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
// Initialise tracing FIRST so auto-instrumentation can patch http/etc.
require("./tracing");
const http = require("http");
const next = require("next");
const { Server } = require("socket.io");
const { parse } = require("url");
const dev = process.env.NODE_ENV !== "production";
const hostname = "0.0.0.0";
const port = parseInt(process.env.PORT || "3000", 10);
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = http.createServer((req, res) => {
try {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
} catch (err) {
console.error("Error handling request:", err);
res.statusCode = 500;
res.end("internal error");
}
});
const io = new Server(server, {
cors: { origin: true, credentials: true },
path: "/socket.io",
transports: ["websocket", "polling"],
});
// Register socket handlers (compiled JS at runtime via require)
const { registerHandlers } = require("./server/socket-handlers.js");
registerHandlers(io);
server.listen(port, hostname, () => {
console.log(`Server ready on :${port}`);
});
process.on("SIGINT", () => {
server.close(() => process.exit(0));
});
});