Skip to content

Commit

Permalink
feat: ✨ Add constants of applocations config
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumeisongsong committed Nov 6, 2024
1 parent 01b1e98 commit 8ca7198
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
10 changes: 4 additions & 6 deletions apps/gateway/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { gatewayConfig } from '@graphql-federation-workspace/applications-config';

import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
const port = gatewayConfig.port;

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
Logger.log(`🚀 Application is running on: ${gatewayConfig.host}:${port}`);
}

bootstrap();
10 changes: 4 additions & 6 deletions apps/users-application/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { userSubGraph } from '@graphql-federation-workspace/applications-config';

import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT || 3000;
const port = userSubGraph.port;

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
);
Logger.log(`🚀 Application is running on: ${userSubGraph.host}:${port}`);
}

bootstrap();
25 changes: 22 additions & 3 deletions libs/application-config/src/lib/applications-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
export function applicationsConfig(): string {
return 'applications-config';
}
const DEFAULT_PORT = {
user: 15001,
task: 15002,
gateway: 3333,
};

// Gateway
export const gatewayConfig = {
host: process.env['GATEWAY_HOST'] ?? undefined,
port: process.env['GATEWAY_PORT'] ?? DEFAULT_PORT.gateway,
};

// Graphql
export const userSubGraph = {
host: process.env['USER_HOST'] ?? undefined,
port: process.env['USER_PORT'] ?? DEFAULT_PORT.user,
};

export const taskSubGraph = {
host: process.env['TASK_HOST'] ?? undefined,
port: process.env['TASK_PORT'] ?? DEFAULT_PORT.task,
};

0 comments on commit 8ca7198

Please sign in to comment.