Skip to content

Commit 077661f

Browse files
committed
middleware
1 parent 73e2ef3 commit 077661f

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/apps/app.guard.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export class ApiKeyGuard implements CanActivate {
99

1010
private excluded = [
1111
/^\/$/,
12-
/^\/webhook(.*)$/,
13-
/^\/(.*)chart(.*)$/,
14-
/^\/(.*)tradingview(.*)$/
12+
/^\/webhook(.*)$/
1513
];
1614

1715
canActivate(
@@ -20,26 +18,18 @@ export class ApiKeyGuard implements CanActivate {
2018
const req: Request = context.switchToHttp().getRequest();
2119

2220

21+
/* disable gurad for path in `exluded` */
2322
if (this.excluded.some((regex) => regex.test(req.path))) {
2423
return true;
2524
}
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-
3425

26+
/* catch x-api-key from header and verify with the env */
3527
const key = req.headers['x-api-key'] ?? req.query.api_key
36-
37-
console.log(req.headers);
3828
if(key == undefined || key == '') {
3929
throw new HttpException('X-API-KEY is not provided.', HttpStatus.UNAUTHORIZED);
4030
}
4131

42-
if(key != process.env.APP_API_KEY ?? 'intervest-sandbox') {
32+
if(key != process.env.APP_API_KEY ?? 'sandbox') {
4333
throw new HttpException('X-API-KEY is not valid.', HttpStatus.UNAUTHORIZED);
4434
}
4535

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async function bootstrap() {
3636
.addTag('Auth', "All about authentication")
3737
.build();
3838
const document = SwaggerModule.createDocument(app, config);
39+
3940
SwaggerModule.setup('docs', app, document);
4041

4142
await app.listen(APP_PORT);

0 commit comments

Comments
 (0)