Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

injecting key-user header in every request to services #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac
## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

## API Gateway

To every request for mission/incident and responder services a user-key header is being added to the request.
To disable it, just open environment.ts and set the **isGatewayEnabled** to false.
35 changes: 35 additions & 0 deletions src/app/interceptor/httpconfig.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Injectable } from '@angular/core';
import {
HttpInterceptor,
HttpRequest,
HttpResponse,
HttpHandler,
HttpEvent,

} from '@angular/common/http';

import { Observable, throwError } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { environment } from '../../environments/environment';

@Injectable() export class HttpConfigInterceptor implements HttpInterceptor {

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if(environment.isGatewayEnabled){
let service = request.url.substr(0, request.url.indexOf("/"));
if (environment.servicesNames.includes(service)){
request = request.clone({
setHeaders: {
"user-key": environment.service.get(service)
}
});
}
}

return next.handle(request).pipe(
map((event: HttpEvent<any>) => {
return event;
}));
}

}
16 changes: 15 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@
// `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.

export var servicesMap = new Map();
servicesMap.set('incident-service', 'd3fa642d9b83043af5b92805ebdaf7d2');
servicesMap.set('alert-service', 'xxx'),
servicesMap.set('responder-service', '884e490b9c52e6c6354b8c6e7cb8ee14'),
servicesMap.set('mission-service', '3865ce20837908ebae41c32a8ae3e829');

export const environment = {
production: false
production: false,
isGatewayEnabled: true,
service: servicesMap,
servicesNames: [
'incident-service',
'alert-service',
'responder-service',
'mission-service',
]
};

/*
Expand Down