egg-ip-address

1.0.0 • Public • Published

egg-ip-address

NPM version build status Test coverage David deps Known Vulnerabilities npm download

开启插件

// 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 异步交流。

License

MIT

Package Sidebar

Install

npm i egg-ip-address

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.65 MB

Total Files

6

Last publish

Collaborators

  • xxllxx