egg-ip-address
v1.0.0
Published
get ip address
Downloads
1
Maintainers
Readme
egg-ip-address
开启插件
// config/plugin.js
exports.ipAddress = {
enable: true,
package: 'egg-ip-address',
};
使用场景
- 根据ip获取ip所在的城市。
详细使用
// {app_root}/app/controller/home.js
const Controller = require('egg').Controller
class HomeController extends Controller {
ip(){
console.log(this.ctx.ipAddress)
this.ctx.body = { ...this.ctx.ipAddress}
}
}
// {app_root}/app/router.js.js
/**
* @param {Egg.Application} app - egg application
*/
module.exports = (app) => {
const {
router,
controller,
config: { apiPrefix }
} = app
router.get('/ip', controller.home.ip)
}
提问交流
请到 egg issues 异步交流。