serverpreconfigured 2.2.2 → 2.2.3

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.
package/dist/logs/logs.js CHANGED
@@ -41,11 +41,22 @@ function stringfyError(err) {
41
41
  }
42
42
  return retData;
43
43
  }
44
+ function getIpFromRequest(req) {
45
+ //@
46
+ let ips = (req.headers['cf-connecting-ip'] ||
47
+ req.headers['x-real-ip'] ||
48
+ req.headers['x-forwarded-for'] ||
49
+ req.ip || '');
50
+ if (typeof (ips) == 'string') {
51
+ ips = ips.split(',');
52
+ }
53
+ return ips[0].trim();
54
+ }
44
55
  function saveInternalErrorLog(req, error, options) {
45
56
  var _a;
46
57
  return __awaiter(this, void 0, void 0, function* () {
47
58
  try {
48
- const ip = req.ip;
59
+ const ip = getIpFromRequest(req);
49
60
  const url = req.originalUrl;
50
61
  //@ts-ignore
51
62
  const userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a.id;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverpreconfigured",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "\"Pre-configured server with authentication system and database integration\"",
5
5
  "main": "dist/server.js",
6
6
  "keywords": [
package/src/logs/logs.ts CHANGED
@@ -36,9 +36,22 @@ function stringfyError(err:any):string{
36
36
  }
37
37
  return retData;
38
38
  }
39
+ function getIpFromRequest(req:Request){
40
+ //@
41
+ let ips = (
42
+ req.headers['cf-connecting-ip'] ||
43
+ req.headers['x-real-ip'] ||
44
+ req.headers['x-forwarded-for'] ||
45
+ req.ip || ''
46
+ );
47
+ if(typeof(ips)=='string'){
48
+ ips=ips.split(',');
49
+ }
50
+ return ips[0].trim();
51
+ }
39
52
  export async function saveInternalErrorLog(req:Request,error:any,options?:{penTestSuspcion?:boolean,severity?:LogSeverity}){
40
53
  try{
41
- const ip=req.ip;
54
+ const ip=getIpFromRequest(req);
42
55
  const url=req.originalUrl;
43
56
  //@ts-ignore
44
57
  const userId=req.user?.id;