Add a new util for getting the client IP address for register info

This commit is contained in:
2026-01-21 22:05:52 -07:00
parent ebae9589d8
commit 532cfcf6e0

View File

@@ -6,6 +6,7 @@ import {
latestBetaVersion,
latestVersion
} from '../info/general'
import { Context } from 'elysia'
export function jsonResponse (data: any, status = 200) {
return new Response(JSON.stringify(data, null, 2), {
@@ -91,3 +92,15 @@ export const genTimestamp = (time: number, extra = 0): string => {
return parts.length ? parts.join(' ') : '1 second'
}
export const getClientIp = (context: Context) => {
const headers = context.headers
if (!headers) return null
return (
headers['cf-connecting-ip'] ??
headers['x-real-ip'] ??
headers['x-forwarded-for']?.split(',')[0]?.trim() ??
null
)
}