项目作者: svtslv

项目描述 :
Maxmind GeoIP2 module for Nest
高级语言: TypeScript
项目地址: git://github.com/svtslv/nestjs-geoip2.git
创建时间: 2020-02-29T00:36:20Z
项目社区:https://github.com/svtslv/nestjs-geoip2

开源协议:

下载


NestJS GeoIP2

NPM Version
Package License

Table of Contents

Description

Integrates MaxMind GeoIP2 with Nest

Installation

  1. npm install nestjs-geoip2 @maxmind/geoip2-node

You can also use the interactive CLI

  1. npx nestjs-modules

Examples

  1. npx geoip2-cli --download --licenseKey=MAXMIND_LICENSE_KEY

GeoIP2Module.forRoot(options, connection?)

  1. import { Module } from '@nestjs/common';
  2. import { GeoIP2Module } from 'nestjs-geoip2';
  3. import { AppController } from './app.controller';
  4. import { join } from 'path';
  5. @Module({
  6. imports: [
  7. GeoIP2Module.forRoot({
  8. config: {
  9. file: join(process.cwd(), 'geoip2-cli', 'GeoLite2-City.mmdb'),
  10. },
  11. }),
  12. ],
  13. controllers: [AppController],
  14. })
  15. export class AppModule {}

GeoIP2Module.forRootAsync(options, connection?)

  1. import { Module } from '@nestjs/common';
  2. import { GeoIP2Module } from 'nestjs-geoip2';
  3. import { AppController } from './app.controller';
  4. import { join } from 'path';
  5. @Module({
  6. imports: [
  7. GeoIP2Module.forRootAsync({
  8. useFactory: () => ({
  9. config: {
  10. file: join(process.cwd(), 'geoip2-cli', 'GeoLite2-City.mmdb'),
  11. },
  12. }),
  13. }),
  14. ],
  15. controllers: [AppController],
  16. })
  17. export class AppModule {}

InjectGeoIP2(connection?)

  1. import { Controller, Get, } from '@nestjs/common';
  2. import { InjectGeoIP2, GeoIP2 } from 'nestjs-geoip2';
  3. @Controller()
  4. export class AppController {
  5. constructor(
  6. @InjectGeoIP2() private readonly geoIP2: GeoIP2,
  7. ) {}
  8. @Get()
  9. async getHello() {
  10. return await this.geoIP2.city('8.8.8.8');
  11. }
  12. }

License

MIT