Features/15 add azure app configuration (#16)
* Adding app config module * adding app context * adding app context and feature flag hooks --------- Co-authored-by: Noah Spannbauer <nspannbauer@sensonix.com>
This commit was merged in pull request #16.
This commit is contained in:
@@ -1,12 +1,34 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
import { AppConfigService, AuthService } from '@noahspan/noahspan-modules';
|
||||
import { FeatureFlagValue } from '@azure/app-configuration';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
constructor(
|
||||
private readonly appConfigService: AppConfigService,
|
||||
private readonly authService: AuthService
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
@Get('featureFlags')
|
||||
async getFeatureFlags(@Query() query: any): Promise<FeatureFlagValue[]> {
|
||||
try {
|
||||
const token: string = await this.authService.getToken(
|
||||
'client_credentials',
|
||||
process.env.CLIENT_ID,
|
||||
process.env.CLIENT_SECRET,
|
||||
'https://azconfig.io'
|
||||
);
|
||||
const featureFlags: FeatureFlagValue[] =
|
||||
await this.appConfigService.getFeatureFlags(
|
||||
token,
|
||||
`${query.key}`,
|
||||
query.label
|
||||
);
|
||||
|
||||
return featureFlags;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { AppConfigModule, AuthModule } from '@noahspan/noahspan-modules';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [
|
||||
AppConfigModule.register({
|
||||
url: process.env.APP_CONFIG_URL
|
||||
}),
|
||||
AuthModule.register({
|
||||
tenantId: process.env.TENANT_ID
|
||||
})
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService]
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user