Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config not propagating to Consul ? #20

Open
iangregsondev opened this issue Apr 4, 2020 · 8 comments
Open

Config not propagating to Consul ? #20

iangregsondev opened this issue Apr 4, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@iangregsondev
Copy link

Hi,

I managed to get it bootstraping now, but I have a problem that it's trying to connect to 127.0.0.1 for consul but i have the BootModule loaded with my config.yaml.

It is supposed to pick this up right?

Hey is there a slack or discord service for nestcloud - just for future reference?

Here is a capture of the screen

image

@iangregsondev
Copy link
Author

It should be using 192.168.1.20 ip from the config.yaml

@iangregsondev
Copy link
Author

The other thing, I am not sure if its correct but on the forRootAsync, the only thing it accepts is a AsyncConsulOptions

    static forRoot(options: ConsulOptions): DynamicModule;
    static forRootAsync(options: AsyncConsulOptions): DynamicModule;

which only contains "inject", it doesn't contain anything else or inherit from ConsulOptions.

@miaowing
Copy link
Member

miaowing commented Apr 4, 2020

The discoveryHost is your service address, not consul address. This is an config example:

consul:
  host: 192.168.1.20
  port: 8500
service:
  discoveryHost: 127.0.0.1
  healthCheck:
    timeout: 1s
    interval: 10s
  maxRetry: 5
  retryInterval: 5000
  id: null
  name: nestcloud-starter-service
  port: 8081

https://github.com/nest-cloud/nestcloud-consul-starter/blob/1062e71c0dd074bf240d623163c6cc399c21d4ad/src/bootstrap-development.yml

@iangregsondev
Copy link
Author

Ah damb :-) Thank you. My bad.

@iangregsondev
Copy link
Author

@miaowing Could i draw your attention to this ?

In the Service module - there is a forRoot and forRootAsync

    static forRoot(options: ServiceOptions): DynamicModule;
    static forRootAsync(options?: ServiceOptions): DynamicModule;

I would like to override the discoveryHost, the normal pattern of nestjs forRootAsync is that it takes a method, usually called "useFactory" - where you can inject things and get access to them i.e.

MongooseModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: async (configService: ConfigService) => ({
    uri: configService.getString('MONGODB_URI'),
  }),
  inject: [ConfigService],
});

Not sure what I can do here ? I need to inject my own Class and don't want to depend on the BOOT

Also in the Consule though there is this

    static forRoot(options: ConsulOptions): DynamicModule;
    static forRootAsync(options: AsyncConsulOptions): DynamicModule;

The forRootAsync only takes in a "inject" nothing else, so I am not able to override anything.

Is this right ? YOu should be able to override it right ?

@miaowing
Copy link
Member

miaowing commented Apr 4, 2020

It's not support useFactory now, I will add this feature in next version.

@iangregsondev
Copy link
Author

Ok - thanks

@miaowing
Copy link
Member

miaowing commented Apr 4, 2020

You can also use the boot module instead of configService and use NEST_BOOT_PROVIDER to inject the boot instance.😁

v0.6.x:

import { NEST_BOOT_PROVIDER, IBoot } from '@nestcloud/common';

MongooseModule.forRootAsync({
  inject: [NEST_BOOT_PROVIDER],
  useFactory: async (boot: IBoot) => ({
    uri: boot.get<string>('MONGODB_URI'),
  }),
});

v0.7.x:

import { BOOT, IBoot } from '@nestcloud/common';

MongooseModule.forRootAsync({
  inject: [BOOT],
  useFactory: async (boot: IBoot) => ({
    uri: boot.get<string>('MONGODB_URI'),
  }),
});

@miaowing miaowing added the enhancement New feature or request label Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants