Skip to content

Commit b8855a0

Browse files
authored
Merge pull request #16 from mkbug-com/feature_ip
Feature ip
2 parents f33ba23 + 6e44080 commit b8855a0

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

bin/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

example/controller/HeaderApiTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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": {

test/controller.header.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)