grpc / grpc/grpc-web

Unable to connect to gRPC Server (ASP.Net Core) hosted in Kestrel from gRPC-Web client in different machine

Open
#1,110 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
9.3k
Forks
802
Avg merge
1d 7h
Merged PRs (30d)
5

Description

Hi,

I have a gRPC Server hosted in Kestrel with gRPC Web enabled. It uses the default certificate.

```
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
services.AddCors(o => o.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding");
}));
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
app.UseCors();

app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService().EnableGrpcWeb()
.RequireCors("AllowAll");
});
}
```

I have a gRPC Web Client running in Javascript.

```
var client = new GreeterClient('https://localhost:5001');
var request = new HelloRequest();
request.setName('World');

client.sayHello(request, {}, (err, response) => {
console.log(response.getMessage());
});
```
If I am trying to connect from same machine using localhost connection works fine. No error call returned successfully.
But when I try to connect from a different machine (after changing ip address) in the same LAN (connected to same router) I am not able to connect.

With the addresses https://192.168.1.102:5001, now connecting from same machine also failed.
Do I need to create a certificate specifically for "192.168.1.102"?

Please let us know if any sample which shows connecting to certificate specified gRPC Server(ASP.Net Kestrel) from JavaScript client from different machine in same LAN.

Thanks
Basanth

Contributor guide

Open the contributing guide

Research direction

Start with the Kestrel and gRPC-Web configuration and the JavaScript client snippet shown in the issue. Reproduce the localhost and LAN-address cases, then inspect the connection and certificate behavior for the LAN address. Done means a JavaScript client on another machine can successfully call the gRPC service over the LAN.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, grpc, javascript
Domain
api, backend-api-design, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.