Skip to content

Commit

Permalink
Merge pull request #2 from waterbustech/migration-v2
Browse files Browse the repository at this point in the history
update .
  • Loading branch information
lambiengcode authored Apr 9, 2024
2 parents f22733d + 120e49d commit 98c2b67
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "waterbus-server-api",
"version": "1.0.0",
"version": "1.0.3",
"description": "Waterbus Server API",
"author": "lambiengcode",
"private": false,
"license": "MIT",
"license": "Apache-2.0",
"scripts": {
"typeorm": "env-cmd ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"build": "nest build",
Expand Down
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AuthModule } from './features/auth/auth.module';
import { UsersModule } from './features/users/users.module';
import { MeetingsModule } from './features/meetings/meetings.module';
import { ChatsModule } from './features/chats/chats.module';
import { EnvironmentConfigModule } from './core/config/env/environment.module';
import { EnvironmentConfigModule } from './core/config/environment/environment.module';

@Module({
imports: [
Expand Down
4 changes: 2 additions & 2 deletions src/core/client-proxy/client-proxy.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Transport,
} from '@nestjs/microservices';
import { EPackage, getIncludeDirs, getProtoPath } from 'waterbus-proto';
import { EnvironmentConfigModule } from '../config/env/environment.module';
import { EnvironmentConfigService } from '../config/env/environments';
import { EnvironmentConfigModule } from '../config/environment/environment.module';
import { EnvironmentConfigService } from '../config/environment/environments';

export const getGrpcClientOptions = (
config: EnvironmentConfigService,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ export class EnvironmentConfigService {
constructor(private configService: ConfigService) {}

getPort(): number {
return Number(this.configService.get<number>('PORT'));
return Number(this.configService.get<number>('APP_PORT'));
}

getApiPrefix(): string {
return this.configService.get<string>('API_PREFIX');
}

getWsGrpcUrl(): string {
return this.configService.get<string>('WEBSOCKET_GRPC_ADDRESS');
}

getAuthGrpcUrl(): string {
return this.configService.get<string>('AUTH_GRPC_URL');
}

getMeetingGrpcUrl(): string {
return this.configService.get<string>('MEETING_GRPC_URL');
}

getPodName(): string {
return this.configService.get<string>('HOSTNAME');
}
Expand Down
22 changes: 8 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { NestFactory, Reflector } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { useContainer } from 'class-validator';
import { ConfigService } from '@nestjs/config';
import { AllConfigType } from './core/config/config.type';
import validationOptions from './utils/validation-options';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { NestExpressApplication } from '@nestjs/platform-express';
import { EPackage, getProtoPath, getIncludeDirs } from 'waterbus-proto';
import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes';
import * as swaggerUi from 'swagger-ui-express';
import { EnvironmentConfigService } from './core/config/environment/environments';

const theme = new SwaggerTheme();

Expand All @@ -23,15 +22,12 @@ async function bootstrap() {
cors: true,
});
useContainer(app.select(AppModule), { fallbackOnErrors: true });
const configService = app.get(ConfigService<AllConfigType>);
const configService = app.get(EnvironmentConfigService);

app.enableShutdownHooks();
app.setGlobalPrefix(
configService.getOrThrow('app.apiPrefix', { infer: true }),
{
exclude: ['/'],
},
);
app.setGlobalPrefix(configService.getApiPrefix(), {
exclude: ['/'],
});
app.enableVersioning({
type: VersioningType.URI,
});
Expand Down Expand Up @@ -59,10 +55,8 @@ async function bootstrap() {

app.use('/docs', swaggerUi.serve, swaggerUi.setup(document, optionsTheme));

const authGrpcUrl = configService.getOrThrow('grpc.authUrl', { infer: true });
const meetingGrpcUrl = configService.getOrThrow('grpc.meetingUrl', {
infer: true,
});
const authGrpcUrl = configService.getAuthGrpcUrl();
const meetingGrpcUrl = configService.getMeetingGrpcUrl();

const authMicroserviceOptions: MicroserviceOptions = {
transport: Transport.GRPC,
Expand Down Expand Up @@ -91,6 +85,6 @@ async function bootstrap() {
app.connectMicroservice(meetingMicroserviceOptions);
await app.startAllMicroservices();

await app.listen(configService.getOrThrow('app.port', { infer: true }));
await app.listen(configService.getPort());
}
void bootstrap();

0 comments on commit 98c2b67

Please sign in to comment.