Handling OPTIONS request using gRPC backend

3,445 views
Skip to first unread message

Vito Tumas

unread,
Jan 4, 2017, 3:41:32 AM1/4/17
to Google Cloud Endpoints
Good afternoon,


What is the correct way to handle OPTIONS requests, when running a gRPC endpoints?

From the latest release notes https://cloud.google.com/endpoints/docs/release-notes I saw that for ESP to accept these requests, allow_cors must be present in the api_configuration.

My configuration setup looks as follows:

type: google.api.Service
config_version
: 3
name
: app.endpoints.my-project.cloud.goog

endpoints
:
 
- name: app.endpoints.my-project.cloud.goog
    allow_cors
: true

title
: Users
apis
:
- name: endpoints.users.User

usage
:
  rules
:
 
- selector: endpoints.users.User.Login
    allow_unregistered_calls
: true


And the http mapping is written in the proto file as follows:

syntax = "proto3";
package endpoints.users;

option go_package
= "proto";
import "google/api/annotations.proto";

service
User {
    rpc
Login (LoginRequest) returns (AuthResponse) {
        option
(google.api.http).post = "/api/v2/users/login";
   
}
}

message
LoginRequest {
   
string email = 1;
   
string password = 2;
}

message
AuthResponse {
   
string token = 1;
}

However when making a OPTIONS request, I get a 404 response.

This makes sense, as I have not defined an option for this request method, but when I add option (google.api.http).option = "/api/v2/users/login"; to the rpc, during the go code generation I get an error that Option "(google.api.http).options" unknown.
I tried adding it using the custom option, however this did not yield any results either.

Currently, to support CORS I'm intercepting the OPTIONS request in the ESP configuration, but this feels a a very hacky way to do things.

Any pointers to solve this problem will be highly appreciated.



Vito

Raphael Simon

unread,
Jan 4, 2017, 12:10:46 PM1/4/17
to Vito Tumas, Google Cloud Endpoints
I think you have to use a custom verb in your proto file to support OPTIONS requests.


--
You received this message because you are subscribed to the Google Groups "Google Cloud Endpoints" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-endpoints/7778fbcc-48e4-4534-b8b1-951aa569283d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

qiwz...@google.com

unread,
Jan 9, 2017, 2:36:06 PM1/9/17
to Google Cloud Endpoints
Sorry, CORS is not supported in Endpoints for gRPC backend yet. 

qiwz...@google.com

unread,
Jan 10, 2017, 8:48:42 PM1/10/17
to Google Cloud Endpoints, qiwz...@google.com
There is a work around for now. 

If the backend server doesn’t support CORS, for example, your backend server is a gRPC server and you are using ESP for gRPC transcoding from HTTP/JSON to gRPC, you may have to use this work around. 

you have to create a custom Nginx config file with CORS supports. Here is a Nginx config example.

Here is instruction on how to use custom Nginx config for GKE.

Nginx config for ESP should contain ESP specific config, otherwise ESP will not work.  One way is to get the ESP Nginx config ESP, modify it to add CORS options.  ESP Nginx config is generated after ESP deployment.   You can ssh into ESP container and get the nginx config from “/etc/nginx/endpoints/” folder.  Here is the instruction on how to SSH into GKE container for ESP. 

Hope it helps.  Thanks.

-Wayne

fabr...@passiolife.com

unread,
May 30, 2017, 6:18:55 PM5/30/17
to Google Cloud Endpoints, qiwz...@google.com
Sorry to review this old thread but I just stumbled on this issue.

Has there been any change on CORS for gRPC backends from January? Is the custom nginx config file still the only viable way?
on another note is the ESP code opensource?

Wayne Zhang

unread,
May 30, 2017, 6:24:57 PM5/30/17
to fabr...@passiolife.com, Google Cloud Endpoints
Sorry, there is no change in this aspect.  But we are working on it.  not ETA yet.   ESP is not open sourced 

Jan Paral

unread,
Aug 22, 2017, 4:35:25 PM8/22/17
to Google Cloud Endpoints, fabr...@passiolife.com, qiwz...@google.com
Hi, is there any update on this?
allow_cors: true still does not work with gRPC backend.
thx, J

Wayne Zhang

unread,
Aug 22, 2017, 4:39:32 PM8/22/17
to Jan Paral, Google Cloud Endpoints, fabr...@passiolife.com
sorry,  we did not add any new feature for CORS.    -Wayne

sh...@node.mu

unread,
Dec 4, 2017, 9:28:09 AM12/4/17
to Google Cloud Endpoints
On Wednesday, 23 August 2017 04:39:32 UTC+8, Wayne Zhang wrote:
sorry,  we did not add any new feature for CORS.    -Wayne

Are there any plans to support CORS for gRPC backends? An ETA would be helpful. 

Wayne Zhang

unread,
Dec 5, 2017, 1:02:24 PM12/5/17
to sh...@node.mu, Google Cloud Endpoints
Sorry, so far there is no change in the ways of supporting CORS for gRPC.  Using the custom Nginx config is the only way.  
Thanks

-Wayne

--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud Endpoints" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-cloud-endpoints/THvCfetfzW8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-endpoints+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-endpoints/8950e117-82ef-4918-ac95-a7fce2d3e238%40googlegroups.com.

sh...@node.mu

unread,
Feb 1, 2018, 1:16:57 AM2/1/18
to Google Cloud Endpoints
If you have a HAProxy sitting in front, you can use the following configuration: https://gist.github.com/vyshane/ae38a21e3d81b97da0b90606d099346a
Reply all
Reply to author
Forward
0 new messages