Updated build scripts - got rid of esbuild because of typeorm problems. Added logging

This commit is contained in:
Dmitriy Shishkov 2021-09-04 17:02:24 +03:00
parent f2057e96f8
commit 0328b4d3d1
No known key found for this signature in database
GPG Key ID: 14358F96FCDD8060
2 changed files with 17 additions and 13 deletions

View File

@ -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": {

View File

@ -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);