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

358
Views
Unable to call gRPC service from Angular client

I am trying to call a gRPC service from Angular application.

If I host the server locally and call it from Anuglar application then it works.

    const client = new HelloWorldServiceClient("http://localhost:5001");
          
    const request = new SayHelloMessage();
    request.setName("User");
    
    client.sayHelloWorld(request, (err: any, response: any) => {
            
    if (err) {
         console.log(err);
         this.response = err;
         return;
    }
    this.response = response.getMessage();
  });

However, when I try to call a gRPC service hosted on a remote server it throws "Response closed without headers" error.

Changed code:

const client = new HelloWorldServiceClient("http://server_name:5001");

If I try to call the same service hosted on a server using NodeJS client then it works too.

NodeJS Code:

var url = "server_name_with_out_http:5001"; // e.g. server_name:5001 and not http://server_name:5001

const client = new HelloWorldServiceClient( 
    url,
    grpc.credentials.createInsecure()
);

var req = { name: "User" };

client.sayHelloWorld(req, (error, reply) => {
    if (!error) {
        console.log(reply.message);
    } else {
        console.log(error);
    }
});

What could be the reason why Angular application is not able to call gRPC service hosted on the server?

Chrome dev tool logs:

enter image description here

enter image description here

enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

This is most likely caused by the common CORS Browser restrictions, and not exactly by angular. This question contains great guidance on CORS.

Calling HTTP services from a Node app (or from postman) will not enforce CORS, while calling it from a market standard browser certainly would.

I know there is far more to it than my next simplified comments but this should give you a starting point (a deeper dive is in the links I shared above)

For browsers to execute XMLHttpRequest's from one website to other domains (or other ports of the same domain):

  1. the browser will send an OPTIONS HTTP request before every real request to the other domain and only allow the actual request when the OPTIONS response headers authorize it.
  2. the "other" website must be configure to reply to OPTIONS requests with specific Headers (Access-Control-Allow-Origin, Access-Control-Request-* ...).

==> If the other server does not reply to OPTIONS requests or does not provide the appropriate headers in the OPTIONS response, you can get a range of different errors, and "Response closed without headers" is one of them.

I believe your gRPC web application is not configured with the proper CORS to authorize communications from the website where you are hosting your angular application (even if it is localhost, you would still need to configure it).

This article has practical guidance on how to configure CORS on .netcore applications

and finally, This github issue / responses contains some more info about a similar error some people faced with gRPC, you might have stepped into the same one. If you have already configured your CORS rules.

over 4 years ago · Santiago Trujillo Report

0

I would recommend to not directly call you backend from your browser client (if that's not want you are doing, let me know) and use a reverse proxy instead. There are many tools out there to do that:

  • Traefik
  • grpcwebproxy
  • envoy

In fact the examples in gRPC's Github repository use envoy (check here) and one of the mail in the grpc-io mail list mentions that directly contacting your backend with your gRPC web frontend is not recommended.

over 4 years ago · Santiago Trujillo Report
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!