Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Deploying Angular app on Nginx is not sending Authorization header to Web Service

I am new to Angular and Docker. I am trying to deploy angular 6 app on Nginx in docker container. My angular app will call web-services with Authorization token. It works fine on my development env with --proxy-config but it does not work in docker container. I tried intercepting the HTTP request and update the URL of web service, but it is not send Authorization headers. How should I call web-services with custom headers?

environment.ts

export const environment = {
production: false,
calculateServiceAPIURL: 'http://localhost:8762'
};


import { Injectable } from '@angular/core';
import {
    HttpRequest,
    HttpHandler,
    HttpEvent,
    HttpInterceptor
} from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from './../environments/environment';

@Injectable({
    providedIn: 'root'
})

export class TokeninceptorService implements HttpInterceptor {

constructor() { }

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    console.log(req.headers);
    req = req.clone({
        url: environment.calculateServiceAPIURL + req.url,
        setHeaders: {
            'Content-Type': 'application/json',
            Authorization: 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJtYWxhdi5wYXJpa2hAeWFob28uY29tIiwidXNlciI6IntcImlkXCI6MSxcImVtYWlsXCI6XCJtYWxhdi5wYXJpa2hAeWFob28uY29tXCIs'
        }
    });
    return next.handle(req);
}

}

Error Message: Access to XMLHttpRequest at 'http://localhost:8762/binaryTree/calculateSum' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

enter image description here

Request and Response headers

enter image description here

Server is not receiving Authorization header due to which it is responding with 401 Unauthorized response status.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!