File tree Expand file tree Collapse file tree 2 files changed +5
-14
lines changed Expand file tree Collapse file tree 2 files changed +5
-14
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,7 @@ export class ApiKeyGuard implements CanActivate {
9
9
10
10
private excluded = [
11
11
/ ^ \/ $ / ,
12
- / ^ \/ w e b h o o k ( .* ) $ / ,
13
- / ^ \/ ( .* ) c h a r t ( .* ) $ / ,
14
- / ^ \/ ( .* ) t r a d i n g v i e w ( .* ) $ /
12
+ / ^ \/ w e b h o o k ( .* ) $ /
15
13
] ;
16
14
17
15
canActivate (
@@ -20,26 +18,18 @@ export class ApiKeyGuard implements CanActivate {
20
18
const req : Request = context . switchToHttp ( ) . getRequest ( ) ;
21
19
22
20
21
+ /* disable gurad for path in `exluded` */
23
22
if ( this . excluded . some ( ( regex ) => regex . test ( req . path ) ) ) {
24
23
return true ;
25
24
}
26
- // if(this.excluded.indexOf(req.path) > -1) {
27
- // return true;
28
- // }
29
- // this.excluded.forEach(path => {
30
- // if(req.path.matchAll(RegExp(/path/)))
31
- // });
32
-
33
-
34
25
26
+ /* catch x-api-key from header and verify with the env */
35
27
const key = req . headers [ 'x-api-key' ] ?? req . query . api_key
36
-
37
- console . log ( req . headers ) ;
38
28
if ( key == undefined || key == '' ) {
39
29
throw new HttpException ( 'X-API-KEY is not provided.' , HttpStatus . UNAUTHORIZED ) ;
40
30
}
41
31
42
- if ( key != process . env . APP_API_KEY ?? 'intervest- sandbox' ) {
32
+ if ( key != process . env . APP_API_KEY ?? 'sandbox' ) {
43
33
throw new HttpException ( 'X-API-KEY is not valid.' , HttpStatus . UNAUTHORIZED ) ;
44
34
}
45
35
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ async function bootstrap() {
36
36
. addTag ( 'Auth' , "All about authentication" )
37
37
. build ( ) ;
38
38
const document = SwaggerModule . createDocument ( app , config ) ;
39
+
39
40
SwaggerModule . setup ( 'docs' , app , document ) ;
40
41
41
42
await app . listen ( APP_PORT ) ;
You can’t perform that action at this time.
0 commit comments