Initial commit: Upload Checkpoint project
This commit is contained in:
commit
c0e3781244
32 changed files with 6121 additions and 0 deletions
13
utils/network.js
Normal file
13
utils/network.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
export function getRealIP(request, server) {
|
||||
let ip = request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip');
|
||||
if (ip?.includes(',')) ip = ip.split(',')[0].trim();
|
||||
if (!ip && server) {
|
||||
ip = server.remoteAddress;
|
||||
}
|
||||
if (!ip) {
|
||||
const url = new URL(request.url);
|
||||
ip = url.hostname;
|
||||
}
|
||||
if (ip?.startsWith('::ffff:')) ip = ip.slice(7);
|
||||
return ip;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue