Skip to content

Commit

Permalink
add lib structure and loggingmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
liglig999 committed Apr 13, 2024
1 parent 07d48d8 commit 685f23e
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
2 changes: 2 additions & 0 deletions apps/auth/src/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { jwtConstants } from './auth.constants';
import { MongooseModule } from '@nestjs/mongoose';
import { UsersService } from './users/users.service';
import { UserSchema } from './users/users.schema';
import { LoggerModule } from '@app/common';

@Module({
imports: [
LoggerModule,
UsersModule,
JwtModule.register({
global: true,
Expand Down
2 changes: 2 additions & 0 deletions apps/auth/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { AuthModule } from './auth.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
Expand All @@ -12,6 +13,7 @@ async function bootstrap() {
},
},
);
app.useLogger(app.get(Logger));

await app.listen();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/gateway/src/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SignInDto } from 'apps/auth/src/dto/sign-in.dto';
import { CreateUserDto } from 'apps/auth/src/dto/create-user.dto';
import { ClientProxy } from '@nestjs/microservices';
import { Observable, tap } from 'rxjs';
import { Public } from '@app/common/lib/auth.guard';
import { Public } from '@app/common';
import { Response, Request } from 'express';

@Controller('auth')
Expand Down
5 changes: 3 additions & 2 deletions apps/gateway/src/gateway.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Module } from '@nestjs/common';
import { Logger, Module } from '@nestjs/common';
import { GatewayController } from './gateway.controller';
import { GatewayService } from './gateway.service';
import { AuthController } from 'apps/gateway/src/auth.controller';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { JwtModule } from '@nestjs/jwt';
import { jwtConstants } from 'apps/auth/src/auth.constants';
import { APP_GUARD } from '@nestjs/core';
import { AuthGuard } from '@app/common/lib/auth.guard';
import { AuthGuard } from '@app/common';

@Module({
imports: [
LoggerModule,
ClientsModule.register([
{
name: 'AUTH_SERVICE',
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions apps/gateway/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
} from '@nestjs/common';
import { ExpressAdapter } from '@nestjs/platform-express';
import { GatewayModule } from './gateway.module';
import { AllGlobalExceptionsFilter } from '@app/common/lib/global-exception-filter';
import { AllGlobalExceptionsFilter } from './global-exception-filter';
import * as cookieParser from 'cookie-parser';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
const app: INestApplication & INestMicroservice = await NestFactory.create(
Expand All @@ -18,7 +19,7 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
app.useGlobalFilters(new AllGlobalExceptionsFilter());
app.use(cookieParser());

app.useLogger(app.get('Logger'));
await app.listen(3000);
}
bootstrap();
17 changes: 0 additions & 17 deletions libs/common/src/database/abstract.repository.ts

This file was deleted.

8 changes: 0 additions & 8 deletions libs/common/src/database/abstract.schema.ts

This file was deleted.

19 changes: 0 additions & 19 deletions libs/common/src/database/database.module.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/common/src/database/index.ts

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions libs/common/src/guards/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './auth.guard';
3 changes: 2 additions & 1 deletion libs/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './database';
export * from './guards';
export * from './logger';
1 change: 1 addition & 0 deletions libs/common/src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './logger.module';
18 changes: 18 additions & 0 deletions libs/common/src/logger/logger.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Module } from '@nestjs/common';
import { LoggerModule as PinoLoggerModule } from 'nestjs-pino';

@Module({
imports: [
PinoLoggerModule.forRoot({
pinoHttp: {
transport: {
target: 'pino-pretty',
options: {
singleLine: true,
},
},
},
}),
],
})
export class LoggerModule {}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
"cookie-parser": "^1.4.6",
"express": "^4.19.2",
"mongoose": "^8.2.4",
"nestjs-pino": "^4.0.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pino-http": "^9.0.0",
"pino-pretty": "^11.0.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
},
Expand Down

0 comments on commit 685f23e

Please sign in to comment.