Use x-forwarded-for

This commit is contained in:
Douglas Barone 2023-10-24 08:01:55 -04:00
parent aea8e3aca8
commit 9165dcf62e

View File

@ -1,12 +1,13 @@
import { Context } from '../trpc' import { Context } from '../trpc'
export function getIpFromContext({ req }: Context) { export function getIpFromContext({ req }: Context) {
if (process.env.NODE_ENV === 'development') return '10.7.16.254'
let ip: string = '' let ip: string = ''
if (req.ips[0]) ip = req.ips[0] if (req.headers['x-forwarded-for'])
else ip = req.ip ip = req.headers['x-forwarded-for'] as string
else ip = req.ip.split('::ffff:')[1]
if (process.env.NODE_ENV === 'development') return '10.7.16.254'
return ip return ip
} }