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

@ -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"
},

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 { 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()

View File

@ -23,6 +23,8 @@ export class RTMTWS implements RTMT {
this.clients = new Map<string, WebSocket>()
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)