I am working on an Angular project where I am trying to consume a gRPC service hosted on an ASP.NET Core server. However, when making requests from my Angular app, I encounter the following CORS-related error messages:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://server-address/Service/GetAll. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.
my address is localhost:4200
.
On the client side, I am using @ngx-grpc
to make the gRPC calls. Here's a snippet of my Angular component:
import { Component } from '@angular/core';
import { Empty } from '@ngx-grpc/well-known-types';
import { TourServiceClient } from 'proto/tour.pbsc';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'angular-grpc';
public tours: any[] = [];
constructor(private client: TourServiceClient) {}
ngOnInit() {
const responseStream = this.client.getAll(new Empty());
console.log(responseStream)
responseStream.subscribe((data:any)=>{
console.log(data)
})
}
}
what the problem ? how can i solve that ?