diff --git a/back/package.json b/back/package.json index 1548611..a4341c9 100644 --- a/back/package.json +++ b/back/package.json @@ -3,18 +3,13 @@ "version": "1.0.0", "description": "Web application for distribution of free classrooms", "scripts": { - "build": "esbuild src/index.ts --bundle --minify --outdir=dist --platform=node", - "start": "esbuild", - "dev": "nodemon" + "build": "tsc", + "start": "node dist/index.js" }, "author": "dm1sh", "license": "MIT", "devDependencies": { "@types/ws": "^7.4.7", - "esbuild": "^0.12.25", - "esbuild-envfile-plugin": "^1.0.1", - "esbuild-node-tsc": "^1.6.1", - "nodemon": "^2.0.12", "typescript": "^4.4.2" }, "dependencies": { diff --git a/back/src/index.ts b/back/src/index.ts index ae85e6c..5eaf3d3 100644 --- a/back/src/index.ts +++ b/back/src/index.ts @@ -6,19 +6,28 @@ import { isMessage, isUpdateMessage } from "./types"; const main = async () => { const connection = await connect(); - const wss = new Server({ - port: Number.parseInt(process.env.PORT || "") || 8081, - }); + const wss = new Server( + { + port: Number.parseInt(process.env.PORT || "") || 8081, + }, + () => console.log(`Started server on ${process.env.PORT || 8081}`) + ); - wss.on("connection", async (ws) => { - ws.send(JSON.stringify(await getRoomList(connection))); + wss.on("connection", async (wsc, req) => { + console.log("New user connected from " + req.socket.remoteAddress); + wsc.send(JSON.stringify(await getRoomList(connection))); - ws.on("message", async (data) => { + wsc.on("message", async (data) => { + console.log("Got message from " + req.socket.remoteAddress); try { const message: unknown = JSON.parse(data.toString()); if (!isMessage(message)) throw new Error("Message corrupted"); if (isUpdateMessage(message)) { + console.log( + `Processing message of \"${message.type}\" type from ${req.socket.remoteAddress}` + ); + const { id, value } = message.args; await updateFree(connection, id, value);