File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed
Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 1- import { Controller , Get , Res , StreamableFile } from '@nestjs/common' ;
1+ import {
2+ Controller ,
3+ Get ,
4+ Param ,
5+ Query ,
6+ Res ,
7+ StreamableFile ,
8+ } from '@nestjs/common' ;
29import { LogService } from './log.service' ;
310import { ApiOperation , ApiTags } from '@nestjs/swagger' ;
411import { Public } from 'src/auth/auth.guard' ;
12+ import { string } from 'joi' ;
513
614@ApiTags ( 'Log' )
715@Controller ( 'log' )
816export class LogController {
917 constructor ( private readonly logService : LogService ) { }
1018
19+ @Public ( )
20+ @Get ( '/test' )
21+ getTest ( ) {
22+ console . log ( 'test' ) ;
23+ return 'test' ;
24+ }
25+
1126 @ApiOperation ( { summary : '로그 파일 확인' } )
1227 @Public ( )
1328 @Get ( )
14- getLog ( ) : StreamableFile {
15- return this . logService . getLogs ( ) ;
29+ getLog ( @ Query ( 'pw' ) pw : string ) : StreamableFile {
30+ return this . logService . getLogs ( pw ) ;
1631 }
1732
1833 @ApiOperation ( { summary : '에러 로그 확인' } )
1934 @Public ( )
2035 @Get ( '/error' )
21- getErrorLog ( ) : StreamableFile {
22- return this . logService . getErrorLogs ( ) ;
36+ getErrorLog ( @ Query ( 'pw' ) pw : string ) : StreamableFile {
37+ return this . logService . getErrorLogs ( pw ) ;
2338 }
2439}
Original file line number Diff line number Diff line change 1- import { Injectable , NotFoundException , StreamableFile } from '@nestjs/common' ;
1+ import {
2+ Injectable ,
3+ NotFoundException ,
4+ StreamableFile ,
5+ UnauthorizedException ,
6+ } from '@nestjs/common' ;
27import { ConfigService } from '@nestjs/config' ;
38import { createReadStream , existsSync } from 'fs' ;
49
@@ -10,15 +15,22 @@ export class LogService {
1015 this . logFilePath = this . configService . get ( 'LOG_FILE_PATH' ) ;
1116 this . errorLogFilePath = this . configService . get ( 'ERROR_LOG_FILE_PATH' ) ;
1217 }
13- getLogs ( ) : StreamableFile {
18+ getLogs ( pw : string ) : StreamableFile {
19+ if ( pw !== this . configService . get ( 'LOG_PW' ) ) {
20+ throw new UnauthorizedException ( '로그 파일을 확인할 권한이 없습니다.' ) ;
21+ }
1422 if ( ! existsSync ( this . logFilePath ) ) {
1523 throw new NotFoundException ( '로그 파일이 존재하지 않습니다.' ) ;
1624 }
1725 return new StreamableFile ( createReadStream ( this . logFilePath ) , {
1826 type : 'text/plain' ,
1927 } ) ;
2028 }
21- getErrorLogs ( ) : StreamableFile {
29+
30+ getErrorLogs ( pw : string ) : StreamableFile {
31+ if ( pw != this . configService . get ( 'LOG_PW' ) ) {
32+ throw new UnauthorizedException ( '로그 파일을 확인할 권한이 없습니다.' ) ;
33+ }
2234 if ( ! existsSync ( this . logFilePath ) ) {
2335 throw new NotFoundException ( '로그 파일이 존재하지 않습니다.' ) ;
2436 }
You can’t perform that action at this time.
0 commit comments