feat: logger and dockerfile
This commit is contained in:
@@ -4,10 +4,12 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import * as Joi from 'joi';
|
||||
import { UsersModule } from './users/users.module';
|
||||
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
|
||||
import { LoggerModule } from 'nestjs-pino';
|
||||
import configuration from './config/configuration';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
LoggerModule.forRoot(),
|
||||
ConfigModule.forRoot({
|
||||
load: [configuration],
|
||||
validationSchema: Joi.object({
|
||||
|
||||
20
src/main.ts
20
src/main.ts
@@ -4,21 +4,37 @@ import {
|
||||
NestFastifyApplication,
|
||||
} from '@nestjs/platform-fastify';
|
||||
import { AppModule } from './app.module';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { ConsoleLogger, LoggerService, ValidationPipe } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Logger } from 'nestjs-pino';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
AppModule,
|
||||
new FastifyAdapter(),
|
||||
{ bufferLogs: true },
|
||||
);
|
||||
|
||||
const logger = app.get(Logger);
|
||||
app.useLogger(logger);
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
}),
|
||||
);
|
||||
|
||||
await app.listen(3000);
|
||||
const configService = app.get<ConfigService>(ConfigService);
|
||||
const port = configService.get<number>('port');
|
||||
|
||||
await app.listen(port, '0.0.0.0', (error, address) => {
|
||||
if (error) {
|
||||
logger.error(error);
|
||||
process.exit(1);
|
||||
} else {
|
||||
logger.log(`Server listening on ${address}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user