feat: 使用中间件 从 jwt 中获取用户信息
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { CommonsModule } from './commons/commons.module';
|
||||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { GraphQLModule } from '@nestjs/graphql';
|
||||
@@ -12,13 +13,13 @@ import { PipelineTasksModule } from './pipeline-tasks/pipeline-tasks.module';
|
||||
import configuration from './commons/config/configuration';
|
||||
import { RedisModule } from 'nestjs-redis';
|
||||
import { WebhooksModule } from './webhooks/webhooks.module';
|
||||
import { RawBodyMiddleware } from './commons/middlewares/raw-body.middleware';
|
||||
import { RawBodyMiddleware } from './commons/middleware/raw-body.middleware';
|
||||
import { GiteaWebhooksController } from './webhooks/gitea-webhooks.controller';
|
||||
import { ParseBodyMiddleware } from './commons/middlewares/parse-body.middleware';
|
||||
import { BullModule } from '@nestjs/bull';
|
||||
import { ParseBodyMiddleware } from './commons/middleware/parse-body.middleware';
|
||||
import { LoggerModule } from 'nestjs-pino';
|
||||
|
||||
import { EtcdModule } from 'nestjs-etcd';
|
||||
import pinoPretty from 'pino-pretty';
|
||||
import { AccountMiddleware } from './commons/middleware/account.middleware';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -66,17 +67,6 @@ import pinoPretty from 'pino-pretty';
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
BullModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
redis: {
|
||||
host: configService.get<string>('db.redis.host', 'localhost'),
|
||||
port: configService.get<number>('db.redis.port', undefined),
|
||||
password: configService.get<string>('db.redis.password', undefined),
|
||||
},
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
ProjectsModule,
|
||||
ReposModule,
|
||||
PipelinesModule,
|
||||
@@ -91,7 +81,15 @@ import pinoPretty from 'pino-pretty';
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
EtcdModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
hosts: configService.get<string>('db.etcd.hosts', 'localhost:2379'),
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
WebhooksModule,
|
||||
CommonsModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, AppResolver],
|
||||
@@ -102,6 +100,8 @@ export class AppModule implements NestModule {
|
||||
.apply(RawBodyMiddleware)
|
||||
.forRoutes(GiteaWebhooksController)
|
||||
.apply(ParseBodyMiddleware)
|
||||
.forRoutes('*')
|
||||
.apply(AccountMiddleware)
|
||||
.forRoutes('*');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user