I have an Angular app in production. Its http requests are wrapped with environment headers so I would like to get all request headers to extract some useful info.
If I use proxy server in development then the task is simple. I just create proxy.conf.js with the content
const PROXY_CONFIG = {
'/context.json': {
'bypass': function (req, res, proxyOptions) {
const objectToReturn = {
headers: req.headers
};
res.end(JSON.stringify(objectToReturn));
return true;
}
}
}
module.exports = PROXY_CONFIG;
And it returns all headers.
But unfortunately this solution doesn't work in production because proxy is only for development in Angular. So I try to use HttpInterceptor now.
@Injectable()
export class HttpConfigInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
console.log('headers in interceptor', req.headers);
return next.handle(req);
}
}
But it seems like the headers array is empty.
How can I get all those headers in HttpInterceptor? Is there any other way to get them ?