File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 1+
12export * from './real-ip.decorator'
Original file line number Diff line number Diff line change 11import { getClientIp } from 'request-ip'
22import { createParamDecorator , ExecutionContext } from '@nestjs/common'
33
4- // noinspection JSUnusedGlobalSymbols
4+ let getClientIp : ( request : any ) => string | null
5+
6+ ( async ( ) => {
7+ try {
8+ const requestIpModule = await import ( 'request-ip' )
9+ getClientIp = requestIpModule . getClientIp
10+ } catch ( error ) {
11+ getClientIp = ( _ : any ) : string | null => {
12+ console . error ( "Le package 'request-ip' n'est pas installé. Veuillez l'installer pour utiliser le décorateur RealIp." )
13+ return null
14+ }
15+ }
16+ } ) ( )
17+
518export const RealIp = createParamDecorator ( ( data : unknown , ctx : ExecutionContext ) => {
619 const request = ctx . switchToHttp ( ) . getRequest ( )
720 return getClientIp ( request )
You can’t perform that action at this time.
0 commit comments