Updated build scripts - got rid of esbuild because of typeorm problems. Added logging
This commit is contained in:
parent
f2057e96f8
commit
0328b4d3d1
@ -3,18 +3,13 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Web application for distribution of free classrooms",
|
"description": "Web application for distribution of free classrooms",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "esbuild src/index.ts --bundle --minify --outdir=dist --platform=node",
|
"build": "tsc",
|
||||||
"start": "esbuild",
|
"start": "node dist/index.js"
|
||||||
"dev": "nodemon"
|
|
||||||
},
|
},
|
||||||
"author": "dm1sh",
|
"author": "dm1sh",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/ws": "^7.4.7",
|
"@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"
|
"typescript": "^4.4.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -6,19 +6,28 @@ import { isMessage, isUpdateMessage } from "./types";
|
|||||||
const main = async () => {
|
const main = async () => {
|
||||||
const connection = await connect();
|
const connection = await connect();
|
||||||
|
|
||||||
const wss = new Server({
|
const wss = new Server(
|
||||||
port: Number.parseInt(process.env.PORT || "") || 8081,
|
{
|
||||||
});
|
port: Number.parseInt(process.env.PORT || "") || 8081,
|
||||||
|
},
|
||||||
|
() => console.log(`Started server on ${process.env.PORT || 8081}`)
|
||||||
|
);
|
||||||
|
|
||||||
wss.on("connection", async (ws) => {
|
wss.on("connection", async (wsc, req) => {
|
||||||
ws.send(JSON.stringify(await getRoomList(connection)));
|
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 {
|
try {
|
||||||
const message: unknown = JSON.parse(data.toString());
|
const message: unknown = JSON.parse(data.toString());
|
||||||
if (!isMessage(message)) throw new Error("Message corrupted");
|
if (!isMessage(message)) throw new Error("Message corrupted");
|
||||||
|
|
||||||
if (isUpdateMessage(message)) {
|
if (isUpdateMessage(message)) {
|
||||||
|
console.log(
|
||||||
|
`Processing message of \"${message.type}\" type from ${req.socket.remoteAddress}`
|
||||||
|
);
|
||||||
|
|
||||||
const { id, value } = message.args;
|
const { id, value } = message.args;
|
||||||
await updateFree(connection, id, value);
|
await updateFree(connection, id, value);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user