Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS error using Go GRPC Gateway #435

Closed
eberkund opened this issue Jan 12, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@eberkund
Copy link

commented Jan 12, 2019

I have a Golang GRPC server on port 9090 and a proxy server using https://github.com/grpc-ecosystem/grpc-gateway on port 9191.

I generated TypeScript code from my .proto file using

protoc -I=proto api.proto \
--js_out=import_style=commonjs:frontend/src/generated \
--grpc-web_out=import_style=typescript,mode=grpcwebtext:frontend/src/generated

However I get this error when I try to make requests

    const url = new URL(window.location.href);
    url.protocol = 'http';
    url.port = '9191';

    // @ts-ignore
    const service = new PublicClient(url.href, {}, {
      // suppressCorsPreflight: true,
    });
    const request = new OpenFolderRequest();
    request.setPath('Hello');

    service.openFolder(request, {},
      (err: grpcWeb.Error, response: OpenFolderResponse) => {
        console.log(response);
        commit('setSession', p);
        commit('setFolder', response.getShotsList());
      });
Access to XMLHttpRequest at 'http://localhost:9191/#//api.Public/OpenFolder' from origin 'http://localhost:3984' has been blocked by CORS policy: Request header field x-user-agent is not allowed by Access-Control-Allow-Headers in preflight response.

When I enable suppressCorsPreflight then I no longer get CORS errors but then I get this weird query string when I make the request and a 404 error

image

I am able to make regular HTTP JSON requests just fine.

@stanley-cheung

This comment has been minimized.

Copy link
Collaborator

commented Jan 14, 2019

I don't believe https://github.com/grpc-ecosystem/grpc-gateway supports grpc-web. You need to use Envoy for that purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.