Skip to content

Commit 1014469

Browse files
committed
chore: add js docs
1 parent be8b111 commit 1014469

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

lib/utils.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,49 @@ const generateUrlPath = (length = 128) => {
4141
return result;
4242
}
4343

44+
/**
45+
* Get the true IP of the request, considering proxy headers and configuration.
46+
* @param {Object} req - The HTTP request object.
47+
* @returns {string} The determined IP address of the request.
48+
*/
4449
const warnedProxyIssues = new Set();
4550

51+
/**
52+
* Get the first value from a header, whether it's a string or an array.
53+
* @param {String|Array} value - The header value(s) to process.
54+
* @returns {String} The first header value.
55+
*/
4656
const firstHeaderValue = (value) => {
4757
if (Array.isArray(value)) return value[0];
4858
return value;
4959
}
5060

61+
/**
62+
* Get the first forwarded IP from a header value.
63+
* @param {String|Array} value - The header value(s) to process.
64+
* @returns {String} The first forwarded IP.
65+
*/
5166
const firstForwardedIp = (value) => {
5267
const header = firstHeaderValue(value);
5368
if (typeof header !== 'string') return header;
5469
return header.split(',')[0].trim();
5570
}
5671

72+
/**
73+
* Warns about a proxy issue only once.
74+
* @param {string} key - The unique key for the warning.
75+
* @param {string} message - The warning message to log.
76+
*/
5777
const warnProxyIssueOnce = (key, message) => {
5878
if (warnedProxyIssues.has(key)) return;
5979
warnedProxyIssues.add(key);
6080
process.log?.warn?.(message);
6181
}
6282

83+
/**
84+
* Get the configured proxy chain from environment variables.
85+
* @returns {Array<string>} An array of configured proxy types.
86+
*/
6387
const getProxyChain = () => {
6488
const configuredProxy = String(process.env.PROXY || 'none')
6589
.toLowerCase()
@@ -82,8 +106,8 @@ const getProxyChain = () => {
82106

83107
/**
84108
* Get the true IP of the request
85-
* @param {Object} req
86-
* @returns
109+
* @param {Object} req - The HTTP request object.
110+
* @returns {string} The determined IP address of the request.
87111
*/
88112
const getIpOfRequest = (req) => {
89113
const headers = req.headers || {};

0 commit comments

Comments
 (0)