@tiledesk/tiledesk-server 2.3.12 → 2.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/app.js +13 -4
  2. package/package.json +1 -1
  3. package/routes/widget.js +18 -3
package/app.js CHANGED
@@ -175,7 +175,6 @@ if (process.env.CREATE_INITIAL_DATA !== "false") {
175
175
 
176
176
 
177
177
 
178
-
179
178
  var app = express();
180
179
 
181
180
 
@@ -341,9 +340,19 @@ function customDetection (req) {
341
340
  // const ip = (req.headers['x-forwarded-for'] || '').split(',').pop().trim() || //https://stackoverflow.com/questions/8107856/how-to-determine-a-users-ip-address-in-node
342
341
  // req.socket.remoteAddress
343
342
 
344
- const ip =
345
- req.headers['x-forwarded-for']?.split(',').shift()
346
- || req.socket?.remoteAddress
343
+
344
+ let ip = req.socket.remoteAddress;
345
+
346
+ const xFor = req.headers['x-forwarded-for'];
347
+ if (xFor ) {
348
+ const xForArr = xFor.split(',');
349
+ if (xForArr && xForArr.length>0) {
350
+ ip = xForArr.shift();
351
+ }
352
+ }
353
+ // const ip =
354
+ // req.headers['x-forwarded-for']?.split(',').shift()
355
+ // || req.socket?.remoteAddress
347
356
 
348
357
  winston.info("standard ip: "+ip); // ip address of the user
349
358
  return ip;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiledesk/tiledesk-server",
3
3
  "description": "The Tiledesk server module",
4
- "version": "2.3.12",
4
+ "version": "2.3.13",
5
5
  "scripts": {
6
6
  "start": "node ./bin/www",
7
7
  "pretest": "mongodb-runner start",
package/routes/widget.js CHANGED
@@ -224,12 +224,27 @@ router.get('/', function(req, res, next) {
224
224
 
225
225
 
226
226
 
227
- const parseIp = (req) =>
228
- req.headers['x-forwarded-for']?.split(',').shift()
229
- || req.socket?.remoteAddress
227
+ // const parseIp = (req) =>
228
+ // req.headers['x-forwarded-for']?.split(',').shift()
229
+ // || req.socket?.remoteAddress
230
230
 
231
+
232
+
233
+ let parseIp = req.socket.remoteAddress;
234
+
235
+ const xFor = req.headers['x-forwarded-for'];
236
+ winston.info("parseIp xFor: "+xFor);
237
+
238
+ if (xFor ) {
239
+ const xForArr = xFor.split(',');
240
+ if (xForArr && xForArr.length>0) {
241
+ parseIp = xForArr.shift();
242
+ winston.info("parseIp xFor parseIp: "+parseIp);
243
+ }
244
+ }
231
245
  winston.info("parseIp: "+parseIp); // ip address of the user
232
246
 
247
+
233
248
  res.json( {ip:ip, ipStandard:ipStandard, parseIp: parseIp} );
234
249
 
235
250