How to configure custom domain for Google Cloud Functions for rendering HTML
Asked Answered
E

2

6

So I have deployed a Google Cloud Function to some place like this:

https://us-central1-my-project.cloudfunctions.net/my-function

I can successfully render a dynamic webpage like this:

https://us-central1-my-project.cloudfunctions.net/my-function?slug=foo

Now, I would like to put this behind a regular URL so it works like this:

https://my-domain.com/some-directory/foo

I would like for it to be https instead of http. And notice that I added some-directory above the foo slug, so there is a little bit of rewriting logic there.

So basically go from here to here:

https://us-central1-my-project.cloudfunctions.net/my-function?slug=foo
https://my-domain.com/some-directory/foo

The question is how to do this. Wondering if you could walk me through how to do it which I think would also help future googlers.

When I search "custom domain for google cloud function" I get this which is for "endpoints" or "openapi" or I don't know, but it doesn't quite seem related. However, I went ahead anyways and changed my DNS nameservers to match what they said:

A     198.51.100.0
A     198.51.100.2
A     198.51.100.4
A     198.51.100.6
AAAA  2001:db8:ffff:32::15
AAAA  2001:db8:ffff:34::15
AAAA  2001:db8:ffff:36::15
AAAA  2001:db8:ffff:38::15

But I am lost as to what to do next. The documentation for Google Cloud is nothing compared to AWS which is unfortunate.

This is as close to what I've found so far, but it's still not even close to getting it working. Maybe this is closer to what I want.

Eckblad answered 5/6, 2019 at 23:56 Comment(2)
This is a suggestion but not your answer. Google Cloud Run works perfectly for your use case plus is serverless containers. Custom domains are a built-in feature.Bazooka
I have found this cloud.google.com/functions/docs/writing/… yet to implement / confirmHoenack
H
1

Actually, is possible using Endpoints for cloud functions:

https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-functions

After you have running your API or function in Cloud Run you just need to do a mapping with your custom domain (https://cloud.google.com/run/docs/mapping-custom-domains) and redeploy the OpenApi specification with the new host.

Howdoyoudo answered 23/4, 2021 at 14:1 Comment(0)
K
0

This is not possible using Google Cloud Functions deployed in a GCP project.

Currently, the only way to map a custom domain to your HTTP/S triggered functions is by using Firebase Functions and Firebase Hosting.

After creating the custom domain, you can configure the domain to handle HTTPS/S triggered functions.

Karyolymph answered 26/8, 2020 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.