add logging

This commit is contained in:
Halit Aksoy 2022-04-11 22:25:49 +03:00
parent 8baa4ba35c
commit e6ce402784
3 changed files with 10 additions and 4 deletions

View File

@ -7,7 +7,7 @@
"start": "node dist/index.js", "start": "node dist/index.js",
"dev": "nodemon src/index.ts", "dev": "nodemon src/index.ts",
"build": "tsc", "build": "tsc",
"test": "jest", "test": "jest",
"coverage": "jest --coverage" "coverage": "jest --coverage"
}, },
"keywords": [], "keywords": [],
@ -15,10 +15,12 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@types/cors": "^2.8.10", "@types/cors": "^2.8.10",
"@types/morgan": "^1.9.3",
"@types/uuid": "^8.3.0", "@types/uuid": "^8.3.0",
"@types/ws": "^7.4.5", "@types/ws": "^7.4.5",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.1", "express": "^4.17.1",
"morgan": "^1.10.0",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"ws": "^7.5.0" "ws": "^7.5.0"
}, },

View File

@ -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 { 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 { Bytes } from "./rtmt/rtmt";
import { createGame, Game, GameMove } from "./mancala"; import { createGame, Game, GameMove } from "./mancala";
import morgan from 'morgan';
const app = express(); const app = express();
app.use(cors()) app.use(cors());
app.use(morgan('dev'));
const server = http.createServer(app); const server = http.createServer(app);
app.get("/", (req: Request, res: Response) => { app.get("/", (req: Request, res: Response) => {
res.send("Hello World"); res.send("Server up and running!");
}); });
app.get("/register/", (req: Request, res: Response) => { app.get("/register/", (req: Request, res: Response) => {
@ -26,7 +28,7 @@ app.get("/register/", (req: Request, res: Response) => {
const port = process.env.PORT || 5000 const port = process.env.PORT || 5000
server.listen(port, () => { server.listen(port, () => {
console.log(`Server started on port ${port} :)`); console.log(`Server started on port ${port}`);
}) })
const rtmt = new RTMTWS() const rtmt = new RTMTWS()

View File

@ -23,6 +23,8 @@ export class RTMTWS implements RTMT {
this.clients = new Map<string, WebSocket>() this.clients = new Map<string, WebSocket>()
wsServer.on("connection", (ws: WebSocket, req: Request) => { wsServer.on("connection", (ws: WebSocket, req: Request) => {
console.log("wsServer connection");
const regexResult = req.url.split(RegExp("\/\?userKey=")); const regexResult = req.url.split(RegExp("\/\?userKey="));
const clientID = regexResult[1] const clientID = regexResult[1]
this.clients.set(clientID, ws) this.clients.set(clientID, ws)