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

Update template configs #41

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.devnet
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
API_URL=https://devnet-api.multiversx.com
NETWORK=devnet
API_URL=https://devnet-api.multiversx.com
3 changes: 2 additions & 1 deletion .env.mainnet
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
API_URL=https://api.multiversx.com
NETWORK=mainnet
API_URL=https://api.multiversx.com
3 changes: 2 additions & 1 deletion .env.testnet
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
API_URL=https://testnet-api.multiversx.com
NETWORK=testnet
API_URL=https://testnet-api.multiversx.com
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ lerna-debug.log*
**/*/config/config.yaml
**/*/config/schema.yaml

!.multiversx/config/config.yaml

# Environment
.env
.env.custom
3 changes: 3 additions & 0 deletions .multiversx/config/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV=infra
NETWORK=
API_URL=
34 changes: 34 additions & 0 deletions .multiversx/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apps:
api:
port: 3000
privatePort: 4000
useCachingInterceptor: true
cacheWarmer:
port: 4001
queueWorker:
port: 4002
transactionsProcessor:
port: 4003
maxLookBehind: 100
libs:
common:
network: ${NETWORK}
urls:
api: ${API_URL}
database:
host: 'localhost'
port: 27017
# username: 'root'
# password: 'root'
name: 'example'
tlsAllowInvalidCertificates: true
redis:
host: '127.0.0.1'
port: 6379
nativeAuth:
# maxExpirySeconds:
acceptedOrigins:
- utils.multiversx.com
security:
admins: []
# rateLimiterSecret:
5 changes: 3 additions & 2 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv';
import { resolve } from 'path';

// Determine which .env file to load based on NODE_ENV
const envPath = `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
const envPath = process.env.NODE_ENV === 'infra' ? '.env' : `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
dotenv.config({
path: resolve(process.cwd(), envPath),
});
Expand All @@ -16,7 +16,7 @@ import { join } from 'path';
import { PrivateAppModule } from './private.app.module';
import { PublicAppModule } from './public.app.module';
import * as bodyParser from 'body-parser';
import { Logger, NestInterceptor } from '@nestjs/common';
import { Logger, NestInterceptor, ValidationPipe } from '@nestjs/common';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import cookieParser from 'cookie-parser';
import { PubSubListenerModule } from '@libs/common';
Expand Down Expand Up @@ -48,6 +48,7 @@ async function bootstrap() {
globalInterceptors.push(new RequestCpuTimeInterceptor(metricsService));

publicApp.useGlobalInterceptors(...globalInterceptors);
publicApp.useGlobalPipes(new ValidationPipe());

const description = readFileSync(join(__dirname, '..', 'docs', 'swagger.md'), 'utf8');

Expand Down
5 changes: 3 additions & 2 deletions apps/cache-warmer/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { ApiMetricsController, CommonConfigModule, DynamicModuleUtils, ExampleModule, HealthCheckController } from '@libs/common';
import { ApiMetricsController, CommonConfigModule, DynamicModuleUtils, HealthCheckController } from '@libs/common';
import { ApiMetricsModule } from '@libs/common';
import { LoggingModule } from '@multiversx/sdk-nestjs-common';
import { AppConfigModule } from './config/app-config.module';
import { ScheduleModule } from '@nestjs/schedule';
import { WarmerService } from './warmer/warmer.service';
import { ServicesModule } from '@libs/services';

@Module({
imports: [
Expand All @@ -13,7 +14,7 @@ import { WarmerService } from './warmer/warmer.service';
ScheduleModule.forRoot(),
CommonConfigModule,
AppConfigModule,
ExampleModule.forRoot(),
ServicesModule,
],
providers: [
DynamicModuleUtils.getPubSubService(),
Expand Down
2 changes: 1 addition & 1 deletion apps/cache-warmer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv';
import { resolve } from 'path';

// Determine which .env file to load based on NODE_ENV
const envPath = `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
const envPath = process.env.NODE_ENV === 'infra' ? '.env' : `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
dotenv.config({
path: resolve(process.cwd(), envPath),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/cache-warmer/src/warmer/warmer.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Inject, Injectable } from "@nestjs/common";
import { Cron } from "@nestjs/schedule";
import { ClientProxy } from "@nestjs/microservices";
import { ExampleService } from "@libs/common";
import { CacheService } from "@multiversx/sdk-nestjs-cache";
import { Locker } from "@multiversx/sdk-nestjs-common";
import { CacheInfo } from "@libs/common/utils/cache.info";
import { ExampleService } from "@libs/services";

@Injectable()
export class WarmerService {
Expand Down
2 changes: 1 addition & 1 deletion apps/queue-worker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv';
import { resolve } from 'path';

// Determine which .env file to load based on NODE_ENV
const envPath = `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
const envPath = process.env.NODE_ENV === 'infra' ? '.env' : `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
dotenv.config({
path: resolve(process.cwd(), envPath),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/transactions-processor/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv';
import { resolve } from 'path';

// Determine which .env file to load based on NODE_ENV
const envPath = `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
const envPath = process.env.NODE_ENV === 'infra' ? '.env' : `.env.${process.env.NODE_ENV ?? 'mainnet'}`;
dotenv.config({
path: resolve(process.cwd(), envPath),
});
Expand Down
1 change: 1 addition & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ apps:
maxLookBehind: 100
libs:
common:
network: ${NETWORK}
urls:
api: ${API_URL}
database:
Expand Down
3 changes: 3 additions & 0 deletions config/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ apps:
maxLookBehind: integer
libs:
common:
network:
type: string
enum: [devnet, testnet, mainnet]
urls:
api: string
database:
Expand Down
2 changes: 2 additions & 0 deletions libs/common/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './sdk.nestjs.config.service.impl';
export * from './common.config.module';
export * from './common.config.service';
export * from './network.config.module';
export * from './network.config.service';
13 changes: 13 additions & 0 deletions libs/common/src/config/network.config.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Global, Module } from "@nestjs/common";
import { NetworkConfigService } from "./network.config.service";

@Global()
@Module({
providers: [
NetworkConfigService,
],
exports: [
NetworkConfigService,
],
})
export class NetworkConfigModule { }
33 changes: 33 additions & 0 deletions libs/common/src/config/network.config.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Injectable } from "@nestjs/common";
import { configuration } from "./configuration";

export interface NetworkConfig {
chainID: 'D' | 'T' | '1';
}

@Injectable()
export class NetworkConfigService {
private readonly devnetConfig: NetworkConfig = {
chainID: 'D',
};
private readonly testnetConfig: NetworkConfig = {
chainID: 'T',
};
private readonly mainnetConfig: NetworkConfig = {
chainID: '1',
};

public readonly config: NetworkConfig;

constructor() {
const network = configuration().libs.common.network;

const networkConfigs = {
devnet: this.devnetConfig,
testnet: this.testnetConfig,
mainnet: this.mainnetConfig,
};

this.config = networkConfigs[network];
}
}
1 change: 1 addition & 0 deletions libs/common/src/entities/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Config {
};
libs: {
common: {
network: "devnet" | "testnet" | "mainnet";
urls: {
api: string;
};
Expand Down
1 change: 1 addition & 0 deletions libs/services/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './example';
export * from './services.module';
export * from './token';
export * from './user';
Loading
Loading