Compare View
Commits (2)
Changes
Showing 5 changed files Side-by-side Diff
CHANGELOG.md
... | ... | @@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d |
4 | 4 | |
5 | 5 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). |
6 | 6 | |
7 | +#### [v0.1.8](https://gitlab.kodesumber.com/komodo/komodo-sdk-push-trx/compare/v0.1.7...v0.1.8) | |
8 | + | |
9 | +- Add clientName on connected client [`0b6da0f`](https://gitlab.kodesumber.com/komodo/komodo-sdk-push-trx/commit/0b6da0fdd1a0fd2379024c3a9ee177c923faa5d9) | |
10 | + | |
7 | 11 | #### [v0.1.7](https://gitlab.kodesumber.com/komodo/komodo-sdk-push-trx/compare/v0.1.6...v0.1.7) |
8 | 12 | |
13 | +> 7 February 2022 | |
14 | + | |
9 | 15 | - Add global.SDK_PUSH_TRX_DEBUG_ALL_GATEWAYS_FROM_CONFIG [`536fc02`](https://gitlab.kodesumber.com/komodo/komodo-sdk-push-trx/commit/536fc0223d0de2be5b962ba6f890caa87c73b7c4) |
10 | 16 | |
11 | 17 | #### [v0.1.6](https://gitlab.kodesumber.com/komodo/komodo-sdk-push-trx/compare/v0.1.5...v0.1.6) |
lib/is-valid-apikey.js
... | ... | @@ -3,9 +3,11 @@ module.exports = (apikey, apikeys) => { |
3 | 3 | if (typeof apikey !== 'string') return false; |
4 | 4 | if (!apikeys || !Array.isArray(apikeys)) return false; |
5 | 5 | |
6 | - return !!apikeys.find((item) => !item.disabled | |
6 | + const matchedApikey = !!apikeys.find((item) => !item.disabled | |
7 | 7 | && ( |
8 | 8 | (typeof item === 'string' && item === apikey) |
9 | 9 | || (item.value === apikey) |
10 | 10 | )); |
11 | + | |
12 | + return matchedApikey || false; | |
11 | 13 | }; |
package-lock.json
1 | 1 | { |
2 | 2 | "name": "komodo-sdk-push-trx", |
3 | - "version": "0.1.7", | |
3 | + "version": "0.1.8", | |
4 | 4 | "lockfileVersion": 2, |
5 | 5 | "requires": true, |
6 | 6 | "packages": { |
7 | 7 | "": { |
8 | 8 | "name": "komodo-sdk-push-trx", |
9 | - "version": "0.1.7", | |
9 | + "version": "0.1.8", | |
10 | 10 | "license": "ISC", |
11 | 11 | "dependencies": { |
12 | 12 | "express": "^4.17.2", |
package.json
server.js
... | ... | @@ -46,11 +46,12 @@ if (!wsListenPort) { |
46 | 46 | // eslint-disable-next-line no-param-reassign |
47 | 47 | ws.isAlive = true; |
48 | 48 | |
49 | - const { remoteAddress, apikey } = client; | |
49 | + const { remoteAddress, apikey, name: clientName } = client; | |
50 | 50 | |
51 | 51 | logger.info(`${MODULE_NAME} F7755A03: Client connected`, { |
52 | 52 | xid: connectionXid, |
53 | 53 | remoteAddress, |
54 | + clientName, | |
54 | 55 | apikey, |
55 | 56 | }); |
56 | 57 | |
... | ... | @@ -164,7 +165,12 @@ if (!wsListenPort) { |
164 | 165 | server.on('upgrade', (req, socket, head) => { |
165 | 166 | const apikey = req.headers && (req.headers.apikey || req.headers.token); |
166 | 167 | |
167 | - if (!isValidApikey(apikey, config.push_trx_server && config.push_trx_server.apikey)) { | |
168 | + const matchedApikey = isValidApikey( | |
169 | + apikey, | |
170 | + config.push_trx_server && config.push_trx_server.apikey, | |
171 | + ); | |
172 | + | |
173 | + if (!matchedApikey) { | |
168 | 174 | rejectConnection(req, socket); |
169 | 175 | return; |
170 | 176 | } |
... | ... | @@ -177,6 +183,7 @@ if (!wsListenPort) { |
177 | 183 | const client = { |
178 | 184 | remoteAddress: req.socket.remoteAddress, |
179 | 185 | apikey, |
186 | + name: matchedApikey.name, | |
180 | 187 | }; |
181 | 188 | |
182 | 189 | wss.emit('connection', ws, req, client); |