How to set public route to HTTP GCF? So, currently the default path something like this.
https://us-central1-poised-breaker-162819.cloudfunctions.net/function-1
But I want to use it in this way
https://myfunction.com
or
https://myfunction.com/thisroute
So actually it is the question of namespacing or even proxying of the requests to appropriate function. How this can be achieved?
Update 1
It seems, like we can use an Endpoints service for that. But it still unclear would it work with GCF or not.
(HyperText Transfer Protocol) The communications protocol used to connect to Web servers on the Internet or on a local network (intranet). The primary function of HTTP is to establish a connection with the server and send HTML pages back to the user's browser.
Cloud Endpoints acts as an API gateway for cloud functions.
For Cloud function https://[CLOUD_FUNCTION_REGION].cloudfunctions.net/my-function,
Set project id in Cloud shell
gcloud config set project [PROJECT_ID]
Deploy ESPv2 Beta to Cloud Run. Replace CLOUD_RUN_SERVICE_NAME with the name that you want to use for the service.
gcloud run deploy CLOUD_RUN_SERVICE_NAME \
--image="gcr.io/endpoints-release/endpoints-runtime-serverless:2" \
--allow-unauthenticated \
--platform managed
At the end of command execution, it will have similar details as below
Service [CLOUD_RUN_SERVICE_NAME] revision [CLOUD_RUN_SERVICE_NAME-00001-ces] has been deployed and is serving 100 percent of traffic at https://CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app
Note host-name receive from the above command (CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app)
Create YAML file api.yaml with OpenAPI spec config:
swagger: '2.0'
info:
title: Cloud Endpoints + GCF
description: Sample API on Cloud Endpoints with a Google Cloud Functions backend
version: 1.0.0
host: CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app
schemes:
- https
produces:
- application/json
paths:
/thisroute:
get:
summary: Custom function route
x-google-backend:
address: https://[CLOUD_FUNCTION_REGION].cloudfunctions.net/my-function
responses:
'200':
description: A successful response
schema:
type: string
Deploy Endpoint configuration:
gcloud endpoints services deploy api.yaml
Now, Cloud function request can route through endpoint https://CLOUD_RUN_SERVICE_NAME-65zrpjcu3q-uk.a.run.app/thisroute.
Also to use custom domain name, need to verifying a domain name. For that follow steps from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With