From e6ce402784d02fb127b844650a2fd91180e6f439 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Mon, 11 Apr 2022 22:25:49 +0300 Subject: [PATCH] add logging --- package.json | 4 +++- src/index.ts | 8 +++++--- src/rtmt/rtmt_websocket.ts | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e1b13b3..abb9edd 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "start": "node dist/index.js", "dev": "nodemon src/index.ts", "build": "tsc", - "test": "jest", + "test": "jest", "coverage": "jest --coverage" }, "keywords": [], @@ -15,10 +15,12 @@ "license": "ISC", "dependencies": { "@types/cors": "^2.8.10", + "@types/morgan": "^1.9.3", "@types/uuid": "^8.3.0", "@types/ws": "^7.4.5", "cors": "^2.8.5", "express": "^4.17.1", + "morgan": "^1.10.0", "uuid": "^8.3.2", "ws": "^7.5.0" }, diff --git a/src/index.ts b/src/index.ts index 2e0fb1d..4ce9940 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,15 +8,17 @@ import { MatchMaker } from "./matcmaker"; import { channel_game_move, channel_leave_game, channel_new_game, channel_on_game_crashed, channel_on_game_start, channel_on_game_update, channel_on_game_user_leave } from "./channel_names"; import { Bytes } from "./rtmt/rtmt"; import { createGame, Game, GameMove } from "./mancala"; +import morgan from 'morgan'; const app = express(); -app.use(cors()) +app.use(cors()); +app.use(morgan('dev')); const server = http.createServer(app); app.get("/", (req: Request, res: Response) => { - res.send("Hello World"); + res.send("Server up and running!"); }); app.get("/register/", (req: Request, res: Response) => { @@ -26,7 +28,7 @@ app.get("/register/", (req: Request, res: Response) => { const port = process.env.PORT || 5000 server.listen(port, () => { - console.log(`Server started on port ${port} :)`); + console.log(`Server started on port ${port}`); }) const rtmt = new RTMTWS() diff --git a/src/rtmt/rtmt_websocket.ts b/src/rtmt/rtmt_websocket.ts index 6494d5a..e146767 100644 --- a/src/rtmt/rtmt_websocket.ts +++ b/src/rtmt/rtmt_websocket.ts @@ -23,6 +23,8 @@ export class RTMTWS implements RTMT { this.clients = new Map() wsServer.on("connection", (ws: WebSocket, req: Request) => { + console.log("wsServer connection"); + const regexResult = req.url.split(RegExp("\/\?userKey=")); const clientID = regexResult[1] this.clients.set(clientID, ws)