diff options
| -rw-r--r-- | ecosystem.config.js | 4 | ||||
| -rw-r--r-- | lib/sockets.js | 30 | ||||
| -rw-r--r-- | lib/utils.js | 2 | ||||
| -rw-r--r-- | package.json | 7 |
4 files changed, 19 insertions, 24 deletions
diff --git a/ecosystem.config.js b/ecosystem.config.js index 14513b6e..ff546fb8 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -2,15 +2,13 @@ module.exports = { apps: [ { name: "coinos", + watch: ["src"], script: "index.js", - watch: ["./"], env: { COMMON_VARIABLE: "true", - NODE_OPTIONS: "--require ./.pnp.js", }, env_production: { NODE_ENV: "production", - NODE_OPTIONS: "--require ./.pnp.js", }, }, ], diff --git a/lib/sockets.js b/lib/sockets.js index e1896b8f..fcca9386 100644 --- a/lib/sockets.js +++ b/lib/sockets.js @@ -41,13 +41,13 @@ broadcast = (type, data) => { } } - Object.values(all).map((ws) => { + Object.values(all).map(ws => { ws.send(JSON.stringify({ type, data })); }); }; -server.on("upgrade", function (req, socket, head) { - wss.handleUpgrade(req, socket, head, function (ws) { +server.on("upgrade", function(req, socket, head) { + wss.handleUpgrade(req, socket, head, function(ws) { wss.emit("connection", ws, req); }); }); @@ -64,13 +64,13 @@ setInterval(() => { } }, 2000); -wss.on("connection", function (ws, req) { +wss.on("connection", function(ws, req) { const id = uuidv4(); ws.beats = 0; ws.send(JSON.stringify({ type: "connected", data: id })); all[id] = ws; - ws.on("message", async (message) => { + ws.on("message", async message => { let type, data; try { ({ type, data } = JSON.parse(message)); @@ -93,7 +93,7 @@ wss.on("connection", function (ws, req) { if (!sockets[username]) sockets[username] = {}; const existing = Object.keys(sockets[username]); if (existing.length > 4) { - const p = existing.find((sid) => sid !== id); + const p = existing.find(sid => sid !== id); sockets[username][p].send(JSON.stringify({ type: "logout" })); setTimeout(() => { if (sockets[username][p]) sockets[username][p].close(); @@ -105,14 +105,14 @@ wss.on("connection", function (ws, req) { let user = await getUser(username); let payments = await user.getPayments({ where: { - account_id: user.account_id, + account_id: user.account_id }, order: [["id", "DESC"]], limit: 12, include: { model: db.Account, - as: "account", - }, + as: "account" + } }); let accounts = await user.getAccounts(); let keys = await user.getKeys(); @@ -128,7 +128,9 @@ wss.on("connection", function (ws, req) { ); } catch (e) { l.error("caught socket error", e.message); - ws.close(); + if (e.message.includes("not found")) + ws.send(JSON.stringify({ type: "logout" })); + setTimeout(ws.close, 1000); } break; case "token": @@ -142,12 +144,12 @@ wss.on("connection", function (ws, req) { const payment = await db.Payment.findOne({ where: { user_id: ws.user.id, - id: data.id, + id: data.id }, include: { model: db.Account, - as: "account", - }, + as: "account" + } }); if (payment) { payment.memo = data.memo; @@ -163,7 +165,7 @@ wss.on("connection", function (ws, req) { } }); - ws.on("close", function () { + ws.on("close", function() { try { const username = names[id]; if (sockets[username] && sockets[username][id]) { diff --git a/lib/utils.js b/lib/utils.js index 17b5d134..23c811c1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -18,7 +18,7 @@ getUser = async (username, transaction) => { } let user = await db.User.findOne(params); - if (!user) throw new Error("User not found"); + if (!user) throw new Error(`User ${username} not found`); return user; }; diff --git a/package.json b/package.json index 0ffa6c27..00f3e213 100644 --- a/package.json +++ b/package.json @@ -57,12 +57,7 @@ "devDependencies": { "nodemon": "^2.0.2", "pino-pretty": "^3.6.1", - "pm2": "^4.4.0", + "pm2": "^4.4.1", "prettier": "^1.18.2" - }, - "dependenciesMeta": { - "bitcoin-core": { - "unplugged": true - } } } |
