silgi 0.38.1 → 0.38.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.38.1";
4
+ const version = "0.38.3";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -279,13 +279,13 @@ declare function useRequest<T extends IncomingMessage>(event: SilgiEvent): T | (
279
279
  originalUrl?: string;
280
280
  });
281
281
  declare function useResponse<T extends ServerResponse>(event: SilgiEvent): ServerResponse;
282
- declare function getIpAddress(event: SilgiEvent): string | boolean;
282
+ declare function getIpAddress(event: SilgiEvent): string;
283
283
  /**
284
284
  * Extract the client's IP address from request headers with high accuracy
285
- * @param req - The incoming HTTP request
285
+ * @param req - The incoming HTTP request (Fetch API Request)
286
286
  * @returns The client's IP address or empty string if not found
287
287
  */
288
- declare function ipAddress(req: IncomingMessage): string;
288
+ declare function ipAddress(req: Request): string;
289
289
 
290
290
  declare function relativeWithDot(from: string, to: string): string;
291
291
  declare function toArray<T>(value: T | T[]): T[];
@@ -940,12 +940,8 @@ function useResponse(event) {
940
940
  return event;
941
941
  }
942
942
  function getIpAddress(event) {
943
- const silgi = useSilgi();
944
- if (silgi.options.present === "nuxt" || silgi.options.present === "nitro" || silgi.options.present === "h3") {
945
- const _ipAddress = ipAddress(event.node.req);
946
- return _ipAddress;
947
- }
948
- return false;
943
+ const _ipAddress = ipAddress(event.req);
944
+ return _ipAddress;
949
945
  }
950
946
  function ipAddress(req) {
951
947
  const headers = [
@@ -981,13 +977,11 @@ function ipAddress(req) {
981
977
  // Used by some CDNs
982
978
  ];
983
979
  for (const header of headers) {
984
- const value = req.headers[header];
980
+ const value = req.headers.get(header);
985
981
  if (!value)
986
982
  continue;
987
983
  let ip;
988
- if (Array.isArray(value)) {
989
- ip = value[0];
990
- } else if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
984
+ if (header === "x-forwarded-for" || header === "forwarded-for" || header === "x-original-forwarded-for") {
991
985
  ip = value.split(",")[0];
992
986
  } else if (header === "forwarded") {
993
987
  const match = value.match(/for=([^;]+)/);
@@ -1000,8 +994,7 @@ function ipAddress(req) {
1000
994
  return cleanIp;
1001
995
  }
1002
996
  }
1003
- const socketIp = req.socket.remoteAddress ?? "";
1004
- return socketIp && isValidIp(socketIp) ? socketIp : "";
997
+ return "";
1005
998
  }
1006
999
  function isValidIp(ip) {
1007
1000
  if (ip === "::1" || ip === "localhost" || ip === "127.0.0.1")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.38.1",
4
+ "version": "0.38.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {