File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
microservices/user-service Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,20 @@ const app = express();
2020app . set ( 'trust proxy' , 1 ) ;
2121
2222app . use ( express . json ( ) ) ;
23+ app . use ( ( req , res , next ) => {
24+ const clientIp = req . headers [ 'x-forwarded-for' ] || req . socket . remoteAddress || req . ip || req . connection . remoteAddress ;
25+ console . log ( `[${ new Date ( ) . toISOString ( ) } ] ${ req . method } ${ req . url } - IP: ${ clientIp } ` ) ;
26+ next ( ) ;
27+ } ) ;
2328
2429app . get ( '/' , ( req , res ) => {
25- res . json ( { messae : 'hello from @microservices-suite/user-service' } ) ;
30+ res . json ( {
31+ messae : 'hello from @microservices-suite/user-service' ,
32+ socket :req . socket . remoteAddress ,
33+ connection :req . connection . remoteAddress ,
34+ ip :req . ip ,
35+ forwarded : req . headers [ 'x-forwarded-for' ] || 'not fwd'
36+ } ) ;
2637} ) ;
2738
2839const server = http . createServer ( app ) ;
You can’t perform that action at this time.
0 commit comments