module description import type { FastifyRequest } from 'fastify' ; import { IncomingMessage } from 'http' ; import { URL } from 'url' ; export const getIp = ( request ) => { const _ = request as any ; let ip = _ . headers [ 'x-forwarded-for' ] || _ . ip || _ . raw . connection . remoteAddress || _ . raw . socket . remoteAddress || undefined ; if ( ip && ip . split ( ',' ) . length > 0 ) { ip = ip . split ( ',' ) [ 0 ] ; } return ip ; } ; export const parseRelativeUrl = ( path ) => { if ( ! path || ! path . startsWith ( '/' ) ) { return new URL ( 'http://a.com' ) ; } return new URL ( 'http://a.com' + path ) ; } ;