path_translation: APPEND_PATH_TO_ADDRESS not working

607 views
Skip to first unread message

i.mar...@gmail.com

unread,
Jul 1, 2019, 8:08:01 AM7/1/19
to Google Cloud Endpoints
Hi,

I followed this tutorial and everything seems to work correctly but something it's unclear. What I want is to have only one https function that's handling requests using express. It's my first time using Cloud Endpoints and OpenAPI but from what I understand, the following configuration (considering "path_translation: APPEND_PATH_TO_ADDRESS") should "redirect" the action and the path to my function.
swagger: '2.0'
info
:
  title
: Test Cloud Endpoints + GCF
  description
: Sample API on Cloud Endpoints with a Google Cloud Functions backend
  version
: 1.0.0
host
: MY_HOST
x
-google-backend:
  address
: https://us-central1-gl-beefastdelivery-staging.cloudfunctions.net/delivery_api
  path_translation
: APPEND_PATH_TO_ADDRESS
schemes
:
 
- https
produces
:
 
- application/json
paths
:
 
/test:
   
get:
      summary
: Greet a user
      operationId
: test
      responses
:
       
'200':
          description
: A successful response
          schema
:
            type
: string

What actually happens is that a GET request to https://{MY_HOST}/test is redirected to my function root (https://us-central1-gl-beefastdelivery-staging.cloudfunctions.net/delivery_api)
Is this a bug, I've missed something or is this a normal behavior/limitation and I am supposed to create one function for each API path?



Mike McDonald

unread,
Jul 1, 2019, 12:36:03 PM7/1/19
to i.mar...@gmail.com, Google Cloud Endpoints
Several things:

1) We don't yet support overriding path_translation behavior. I've submitted the changes, but it's taking some time to roll out to production (especially since the fourth of July holiday in the US means we likely won't have releases this week).

2) The path_translation behavior for where you've placed x-google-backend is already APPEND_PATH_TO_ADDRESS. I would assume that:

curl https://{HOST}/test -> https://us-central1-gl-beefastdelivery-staging.cloudfunctions.net/delivery_api/test (since "APPEND_PATH_TO_ADDRESS" should do just that)

Note that in the function, the URL path is /test, so I assume you could use express semi-normally.

3) Is there a reason you don't want to use GAE Standard or Cloud Run? They seem to be a better fit for what you're looking for (running an Express app).

Thanks,
--Mike


--
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/9bb28685-c90e-41c1-98d0-552d17ed1ce5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Michael McDonald | Product Manager, Serverless | mpmcd...@google.com | 1-844-THE-FIRE 

i.mar...@gmail.com

unread,
Jul 1, 2019, 3:20:02 PM7/1/19
to Google Cloud Endpoints
Thanks for the clarification with path_translation. 
Regarding the 2nd point, I've seen in the docs that this is the default behavior but it didn't work and that's why I've tried using APPEND_PATH_TO_ADDRESS explicitly. Here is the relevant part extracted from my code:
const api = express();
api.use(bodyParser.json());

api.get('/', (req, res) => {
    res.send('Hello root!');
});


api.get('/test', (req, res) => {
    res.send('Hello api 2!');
});
export const webApi = functions.https.onRequest(api);
With this and the above mentioned openAPI config, I get "Hello root!" when I am calling https://{HOST}/test I've also tried creating an additional route in openAPI and it is also redirected to the base function URL. Another thing I've tried is to explicitly set the x-google-backend address for the /test path as https://us-central1-gl-beefastdelivery-staging.cloudfunctions.net/delivery_api/test but this results in 401: Unauthorised.

My first try was with Cloud Functions because I was already working with Firebase and it was an easier and natural move. For some reason, Firebase stuff looks a bit less scary than Google Cloud stuff, even though, in the end, both are easy to use. Also, somehow, the table from this page (https://cloud.google.com/endpoints/docs/choose-endpoints-option) made me think that AppEngine Standard can be used with Endpoints only with java or python. Now, that you mentioned it, I looked closer to the table and I found this https://cloud.google.com/endpoints/docs/openapi/get-started-app-engine-standard. It actually makes sense to work and I'll try to implement the API this way but, if this is a bug and not just my mistake, I am still open to help.

luni, 1 iulie 2019, 19:36:03 UTC+3, Mike McDonald a scris:
Several things:

1) We don't yet support overriding path_translation behavior. I've submitted the changes, but it's taking some time to roll out to production (especially since the fourth of July holiday in the US means we likely won't have releases this week).

2) The path_translation behavior for where you've placed x-google-backend is already APPEND_PATH_TO_ADDRESS. I would assume that:

curl https://{HOST}/test -> https://us-central1-gl-beefastdelivery-staging.cloudfunctions.net/delivery_api/test (since "APPEND_PATH_TO_ADDRESS" should do just that)

Note that in the function, the URL path is /test, so I assume you could use express semi-normally.

3) Is there a reason you don't want to use GAE Standard or Cloud Run? They seem to be a better fit for what you're looking for (running an Express app).

Thanks,
--Mike


To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-endpoints+unsub...@googlegroups.com.

Qiwen Zhang

unread,
Jul 8, 2019, 2:19:50 PM7/8/19
to Google Cloud Endpoints
Hi.  It is a bug.  I just filed this issue to fix it.  Thanks.  -Wayne
Reply all
Reply to author
Forward
0 new messages