Skip to content
Snippets Groups Projects
Commit 0a28dd66 authored by Steve Reis's avatar Steve Reis
Browse files

WIP: interceptor add headers

parent 9e37209d
No related branches found
No related tags found
No related merge requests found
......@@ -5,20 +5,31 @@ import {
ExecutionContext,
CallHandler,
} from '@nestjs/common';
import { GqlExecutionContext } from '@nestjs/graphql';
import { IncomingMessage } from 'http';
import { Observable } from 'rxjs';
@Injectable()
export class HeadersInterceptor implements NestInterceptor {
constructor(private httpService: HttpService) {}
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const request = context.switchToHttp().getRequest<Request>();
intercept(context: GqlExecutionContext, next: CallHandler): Observable<any> {
// cleaner : add only the auth header (should find the name)
//console.log(context.switchToHttp().getRequest());
console.log('interceptor headers', request);
//this.httpService.axiosRef.defaults.headers = request.headers;
switch (context.getType()) {
case 'http': {
const ctx = context.switchToHttp();
const request = ctx.getRequest<Request>();
this.httpService.axiosRef.defaults.headers = request.headers;
break;
}
case 'graphql': {
const ctx = GqlExecutionContext.create(context);
const req: IncomingMessage = ctx.getContext().req;
this.httpService.axiosRef.defaults.headers = req.headers;
break;
}
}
return next.handle();
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment