How to configure custom domain for Google Cloud Functions for rendering HTML

徘徊边缘 提交于 2021-02-07 19:17:04

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/56469437/how-to-configure-custom-domain-for-google-cloud-functions-for-rendering-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!