Add a new util for getting the client IP address for register info
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
latestBetaVersion,
|
latestBetaVersion,
|
||||||
latestVersion
|
latestVersion
|
||||||
} from '../info/general'
|
} from '../info/general'
|
||||||
|
import { Context } from 'elysia'
|
||||||
|
|
||||||
export function jsonResponse (data: any, status = 200) {
|
export function jsonResponse (data: any, status = 200) {
|
||||||
return new Response(JSON.stringify(data, null, 2), {
|
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'
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user