I am developing an API restful in Go and my frontend in Angular (no AngularJS), but when I call my API from my Web App in Angular I do not see my headers in my backend, in special case my authorization header, because my API has authentication based in JWT.
Also I want to mention that I am using Postman and Go Request client to test my app and my headers are delivered in my API without problems.
Attached below is the CORS of my backend and the API call from my frontend.
My backend:
func Cors() gin.HandlerFunc {
log.Println("CORS Middleware")
return func(c *gin.Context) {
c.Writer.Header().Add("Access-Control-Allow-Origin", "*")
c.Next()
}
}
My Frontend:
getData() {
const auth = `Bearer ${this.token}`;
const headers = new Headers({
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Authorization': auth,
});
const options = new RequestOptions(headers);
console.log(headers); //Here I can see
const products = this.http.get('localhost:8000/api/products', options )
.subscribe((response: Response) => {
this.data = response.json();
});
return products;
}
Thanks and sorry for my english, I think that my CORS causes problems.