What is the expected output for app_identity.get_default_version_hostname()

88 views
Skip to first unread message

NP

unread,
Jan 15, 2019, 2:35:30 PM1/15/19
to Google App Engine
Hello,


.....By default, App Engine apps are served from URLs in the form http://<your_app_id>.appspot.com, where the app ID is part of the hostname. If an app is served from a custom domain, it may be necessary to retrieve the entire hostname component. You can do this using the app_identity.get_default_version_hostname() method....


However, when I print the output for app_identity.get_default_version_hostname(), it gives me http://<project_name>.appspot.com.. not my custom domain. But if I look at my log files, the entry for host under the "protopayload" is my custom domain i.e. I see something like..... 

protoPayload: {
appEngineRelease: 
appId: <APP_ID>
cost: 1.16787e-7 
endTime: 
finished: true 
first: true 
host: "<MY_CUSTOM_DOMAIN_URL>


My questions are

1) Does it mean app_identity.get_default_version_hostname() is not meant to give me my custom domain url?

2) If #1 is true, how do I programmatically determine the custom domain url? I don't want to hardcode it so that the same code can be used for different projects and different custom domain names

George (Cloud Platform Support)

unread,
Jan 16, 2019, 4:44:38 PM1/16/19
to Google App Engine
In reply to your first question, you are right: google.appengine.api.app_identity.app_identity.get_default_version_hostname() gets the standard host name of the default version of the app. For example, if your application_id is my-app, then the result might be my-app.appspot.com. You may check this on the "google.appengine.api.app_identity.app_identity module" page

In what concerns question 2), there does not seem to be a compelling need to programmatically obtain the custom name instead, as the standard host name and the custom one point to the same site, and can be used interchangeably. Mapping between custom ID has been performed by project owners, and the information should be readily available, even if not by means of an API call from your code. In other words, you are supposed to know your custom domain URL already. 

NP

unread,
Jan 16, 2019, 7:21:00 PM1/16/19
to Google App Engine
Thanks for the response.

With regards to question 2, if the project is being deployed by different users (hence different domains), you wouldn't know the custom domain URL upfront. A work around is to have user enter the value, which then gets stored and then you read it. I just wanted to know if there was an API that provided this value directly so that I wouldn't be reinventing the wheel.

Mohammad I (Cloud Platform Support)

unread,
Jan 23, 2019, 3:39:12 PM1/23/19
to Google App Engine

Hello,


Please look into this document, which describes using the app_identity.get_default_version_hostname() method you can retrieve the entire hostname component if an app is served from a custom domain where the app ID is part of the hostname (i.e. http://<your_app_id>.appspot.com). So as George mentioned earlier you are getting expected behavior from the app_identity.get_default_version_hostname() method.


Regarding your second question, if your domain is mapped to your App Engine app you can use the apps.domainMappings.list method to list your resource records. You can also achieve this using Console or gcloud command "gcloud app domain-mappings list".  You can get more details on this at number four point of this document and on gcloud command “gcloud app domain-mappings” here. If your domain is not mapped, to programmatically map your domain to your App Engine app you can use the app.domainMappings.create method. You can find more about the methods available with REST Resource: apps.domainMappings here.


Reply all
Reply to author
Forward
0 new messages