A NestCloud component for providing consul api based on node-consul.
$ npm i --save @nestcloud/consul consul
import { Module } from '@nestjs/common';
import { ConsulModule } from '@nestcloud/consul';
import { BOOT } from '@nestcloud/common';
@Module({
imports: [
ConsulModule.forRootAsync({ inject: [BOOT] })
],
})
export class AppModule {}
consul:
host: localhost
port: 8500
import { Injectable } from '@nestjs/common';
import * as Consul from 'consul';
import { InjectConsul } from '@nestcloud/consul';
@Injectable()
export class TestService {
constructor(
@InjectConsul() private readonly consul: Consul
) {
}
}
import { Injectable } from '@nestjs/common';
import { WatchKV } from '@nestcloud/consul';
@Injectable()
export class TestService {
@WatchKV('test_key', 'yaml', {})
private readonly config: any;
}
Import consul module.
field | type | description |
---|---|---|
options.host | string | consul host |
options.port | string | consul port |
options.secure | boolean | security or not |
options.ca | string[] | certs |
options.defaults | any | default consul config |
Import consul module.
field | type | description |
---|---|---|
options.inject | string[] | BOOT |
see node-consul
Inject consul kv to the class attribute, it will update immediately when consul kv update.
field | type | description |
---|---|---|
name | string | consul key |
options.type | text json yaml | value type |
options.defaults | any | default value |
- Author - NestCloud
NestCloud is MIT licensed.