File tree Expand file tree Collapse file tree 4 files changed +36
-2
lines changed
Expand file tree Collapse file tree 4 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,9 @@ module.exports = {
4545 ctx . type = null ;
4646 ctx . get = req . get . bind ( req ) ;
4747 ctx . set = res . set . bind ( res ) ;
48-
48+ ctx . ip = req . ip ;
49+ ctx . ips = req . ips ;
50+
4951 return ctx ;
5052 } ,
5153 LOG ( msg , ...other ) {
Original file line number Diff line number Diff line change @@ -9,4 +9,12 @@ module.exports = class HeaderApiTest extends BaseController {
99 this . set ( 'from-header' , 'from-header' )
1010 return ''
1111 }
12+
13+ getIpAction ( ) {
14+ return this . ip ;
15+ }
16+
17+ getIpsAction ( ) {
18+ return this . ips ;
19+ }
1220}
Original file line number Diff line number Diff line change 11{
22 "name" : " mkbugjs" ,
3- "version" : " 1.5.1 " ,
3+ "version" : " 1.5.2 " ,
44 "description" : " An OOP style declare Nodejs Web framework base on Express.js" ,
55 "main" : " index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -26,4 +26,28 @@ describe("Controller Header", () => {
2626 expect ( ret . header [ 'from-header' ] ) . toBe ( 'from-header' ) ;
2727 }
2828 } ) ;
29+
30+ it ( "Ip test" , async ( ) => {
31+ let ret = null ;
32+ try {
33+ ret = await request . get ( 'http://localhost:3000/api/headerapitest/ip' )
34+ } catch ( err ) {
35+ ret = err ;
36+ } finally {
37+ expect ( ret . status ) . toBe ( 200 ) ;
38+ expect ( ret . text ) . toBe ( '::ffff:127.0.0.1' ) ;
39+ }
40+ } ) ;
41+
42+ it ( "Ip test" , async ( ) => {
43+ let ret = null ;
44+ try {
45+ ret = await request . get ( 'http://localhost:3000/api/headerapitest/ips' )
46+ } catch ( err ) {
47+ ret = err ;
48+ } finally {
49+ expect ( ret . status ) . toBe ( 200 ) ;
50+ expect ( ret . text ) . toBe ( '[]' ) ;
51+ }
52+ } ) ;
2953} )
You can’t perform that action at this time.
0 commit comments