fix: exception filter

This commit is contained in:
Innei
2021-09-05 15:48:09 +08:00
parent 3515851a70
commit a17afd068f
9 changed files with 20 additions and 12 deletions

4
.gitignore vendored
View File

@@ -31,4 +31,6 @@ lerna-debug.log*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json
paw.paw

View File

@@ -13,7 +13,7 @@ module.exports = {
apps: [
{
name: 'mx-space-server@next',
script: 'dist/main.js',
script: 'dist/src/main.js',
autorestart: true,
instances: 'max',
exec_mode: 'cluster',

BIN
paw.paw

Binary file not shown.

View File

@@ -56,7 +56,8 @@ export class AllExceptionsFilter implements ExceptionFilter {
`[${new Date().toISOString()}] ${decodeURI(request.raw.url)}: ${
(exception as any)?.response?.message ||
(exception as myError)?.message
} \n ${(exception as Error).stack || ''} \n`,
}\n`,
// ${(exception as Error).stack || ''}\n`,
{ encoding: 'utf-8', flag: 'a+' },
)
}

View File

@@ -7,11 +7,13 @@ import { AuthController } from './auth.controller'
import { AuthService } from './auth.service'
import { JwtStrategy } from './jwt.strategy'
export const __secret =
SECURITY.jwtSecret || process.env.SECRET || 'asdhaisouxcjzuoiqdnasjduw'
const jwtModule = JwtModule.registerAsync({
useFactory() {
return {
secret:
SECURITY.jwtSecret || process.env.SECRET || 'asdhaisouxcjzuoiqdnasjduw',
secret: __secret,
signOptions: {
expiresIn: '7d',
},

View File

@@ -10,6 +10,7 @@
import { Injectable, UnauthorizedException } from '@nestjs/common'
import { PassportStrategy } from '@nestjs/passport'
import { ExtractJwt, Strategy, StrategyOptions } from 'passport-jwt'
import { __secret } from './auth.module'
import { AuthService } from './auth.service'
import { JwtPayload } from './interfaces/jwt-payload.interface'
@@ -18,7 +19,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.SECRET || 'asdhaisouxcjzuoiqdnasjduw',
secretOrKey: __secret,
ignoreExpiration: false,
} as StrategyOptions)
}

View File

@@ -1,7 +1,7 @@
import { Injectable, Logger } from '@nestjs/common'
import chalk from 'chalk'
import { mkdirSync } from 'fs'
import { DATA_DIR, TEMP_DIR } from 'src/constants/path.constant'
import { DATA_DIR, LOGGER_DIR, TEMP_DIR } from 'src/constants/path.constant'
@Injectable()
export class InitService {
@@ -23,5 +23,7 @@ export class InitService {
this.logger.log(chalk.blue('数据目录已经建好: ' + DATA_DIR))
mkdirSync(TEMP_DIR, { recursive: true })
this.logger.log(chalk.blue('临时目录已经建好: ' + TEMP_DIR))
mkdirSync(LOGGER_DIR, { recursive: true })
this.logger.log(chalk.blue('日志目录已经建好: ' + LOGGER_DIR))
}
}

View File

@@ -17,7 +17,7 @@ import { IsMaster } from '~/common/decorator/role.decorator'
import { getAvatar } from '~/utils/index.util'
import { AuthService } from '../auth/auth.service'
import { RolesGuard } from '../auth/roles.guard'
import { LoginDto, UserDto, UserPatchDto } from './dto/user.dto'
import { LoginDto, UserDto, UserPatchDto } from './user.dto'
import { UserDocument, UserModel } from './user.model'
import { UserService } from './user.service'

View File

@@ -44,22 +44,22 @@ class UserOptionDto {
export class UserDto extends UserOptionDto {
@ApiProperty()
@IsString()
@IsNotEmpty()
@IsNotEmpty({ message: '用户名?' })
readonly username: string
@IsString()
@ApiProperty()
@IsNotEmpty()
@IsNotEmpty({ message: '密码?' })
readonly password: string
}
export class LoginDto {
@ApiProperty({ required: true })
@IsString()
@IsString({ message: '用户名?' })
username: string
@ApiProperty({ required: true })
@IsString()
@IsString({ message: '密码?' })
password: string
}