78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { LoggerModule } from 'nestjs-pino';
|
|
import * as Joi from 'joi';
|
|
|
|
@Module({
|
|
imports: [
|
|
// Configuration
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
validationSchema: Joi.object({
|
|
NODE_ENV: Joi.string()
|
|
.valid('development', 'production', 'test')
|
|
.default('development'),
|
|
PORT: Joi.number().default(4000),
|
|
DATABASE_HOST: Joi.string().required(),
|
|
DATABASE_PORT: Joi.number().default(5432),
|
|
DATABASE_USER: Joi.string().required(),
|
|
DATABASE_PASSWORD: Joi.string().required(),
|
|
DATABASE_NAME: Joi.string().required(),
|
|
REDIS_HOST: Joi.string().required(),
|
|
REDIS_PORT: Joi.number().default(6379),
|
|
REDIS_PASSWORD: Joi.string().required(),
|
|
JWT_SECRET: Joi.string().required(),
|
|
JWT_ACCESS_EXPIRATION: Joi.string().default('15m'),
|
|
JWT_REFRESH_EXPIRATION: Joi.string().default('7d'),
|
|
}),
|
|
}),
|
|
|
|
// Logging
|
|
LoggerModule.forRootAsync({
|
|
useFactory: (configService: ConfigService) => ({
|
|
pinoHttp: {
|
|
transport:
|
|
configService.get('NODE_ENV') === 'development'
|
|
? {
|
|
target: 'pino-pretty',
|
|
options: {
|
|
colorize: true,
|
|
translateTime: 'SYS:standard',
|
|
ignore: 'pid,hostname',
|
|
},
|
|
}
|
|
: undefined,
|
|
level: configService.get('NODE_ENV') === 'production' ? 'info' : 'debug',
|
|
},
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
|
|
// Database
|
|
TypeOrmModule.forRootAsync({
|
|
useFactory: (configService: ConfigService) => ({
|
|
type: 'postgres',
|
|
host: configService.get('DATABASE_HOST'),
|
|
port: configService.get('DATABASE_PORT'),
|
|
username: configService.get('DATABASE_USER'),
|
|
password: configService.get('DATABASE_PASSWORD'),
|
|
database: configService.get('DATABASE_NAME'),
|
|
entities: [],
|
|
synchronize: configService.get('DATABASE_SYNC', false),
|
|
logging: configService.get('DATABASE_LOGGING', false),
|
|
}),
|
|
inject: [ConfigService],
|
|
}),
|
|
|
|
// Application modules will be added here
|
|
// RatesModule,
|
|
// BookingsModule,
|
|
// AuthModule,
|
|
// etc.
|
|
],
|
|
controllers: [],
|
|
providers: [],
|
|
})
|
|
export class AppModule {}
|