Reset logs
This commit is contained in:
@@ -33,10 +33,8 @@
|
||||
"cross-env": "10.0.0",
|
||||
"dayjs": "1.11.13",
|
||||
"jwks-rsa": "3.2.0",
|
||||
"nestjs-pino": "4.4.0",
|
||||
"passport": "0.7.0",
|
||||
"passport-jwt": "4.0.1",
|
||||
"pino-http": "10.5.0",
|
||||
"reflect-metadata": "0.2.2",
|
||||
"rxjs": "7.8.1"
|
||||
},
|
||||
@@ -57,7 +55,6 @@
|
||||
"eslint-plugin-prettier": "5.2.2",
|
||||
"globals": "16.0.0",
|
||||
"jest": "30.0.0",
|
||||
"pino-pretty": "13.1.1",
|
||||
"prettier": "3.4.2",
|
||||
"prisma": "6.14.0",
|
||||
"source-map-support": "0.5.21",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Module, MiddlewareConsumer } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { LoggerModule } from 'nestjs-pino';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
@@ -14,28 +13,7 @@ import { AuthController } from './auth/auth.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
}),
|
||||
LoggerModule.forRootAsync({
|
||||
useFactory: () => ({
|
||||
pinoHttp: {
|
||||
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
|
||||
transport:
|
||||
process.env.NODE_ENV !== 'production'
|
||||
? {
|
||||
target: 'pino-pretty',
|
||||
options: {
|
||||
colorize: true,
|
||||
levelFirst: true,
|
||||
translateTime: 'SYS:HH:MM:ss.l',
|
||||
ignore: 'pid,hostname',
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
ConfigModule.forRoot(),
|
||||
PrismaModule,
|
||||
VideosModule,
|
||||
AuthModule,
|
||||
|
||||
60
src/main.ts
60
src/main.ts
@@ -1,63 +1,13 @@
|
||||
import {
|
||||
ClassSerializerInterceptor,
|
||||
Logger,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ClassSerializerInterceptor } from '@nestjs/common';
|
||||
import { NestFactory, Reflector } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { Logger as PinoLogger } from 'nestjs-pino';
|
||||
|
||||
async function bootstrap() {
|
||||
// Create app with default logger first
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
logger: ['error', 'warn', 'log', 'debug', 'verbose'],
|
||||
});
|
||||
|
||||
// Then set up Pino logger
|
||||
const pinoLogger = app.get(PinoLogger, { strict: false });
|
||||
if (pinoLogger) {
|
||||
app.useLogger(pinoLogger);
|
||||
}
|
||||
|
||||
const logger = app.get(Logger);
|
||||
const app = await NestFactory.create(AppModule);
|
||||
const reflector = app.get(Reflector);
|
||||
|
||||
// Global pipes and interceptors
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
transform: true,
|
||||
forbidNonWhitelisted: true,
|
||||
}),
|
||||
);
|
||||
app.useGlobalInterceptors(new ClassSerializerInterceptor(reflector));
|
||||
|
||||
app.useGlobalInterceptors(
|
||||
new ClassSerializerInterceptor(reflector, {
|
||||
excludePrefixes: ['_'],
|
||||
}),
|
||||
);
|
||||
|
||||
// Enable CORS
|
||||
app.enableCors({
|
||||
origin: process.env.CORS_ORIGIN || '*',
|
||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
// Start the application
|
||||
const port = process.env.PORT || 3000;
|
||||
await app.listen(port);
|
||||
|
||||
logger.log(`🚀 Application is running on port: ${port}`);
|
||||
logger.log(`📡 Environment: ${process.env.NODE_ENV || 'development'}`);
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
logger.debug('🔧 Debug mode is enabled');
|
||||
}
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
|
||||
bootstrap().catch((error) => {
|
||||
// Use console.error here since the logger might not be available
|
||||
console.error('Failed to start application', error);
|
||||
process.exit(1);
|
||||
});
|
||||
void bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user