Search code examples
google-cloud-platformgoogle-cloud-shell

Google Cloud Shell: How to find your web preview URL


When using Google Cloud Shell on the Google Cloud Platform console, clicking on the "web preview" button will redirect you to a URL that is serving your app on port 8080.

So, for example, the URL for your instance may be something like:

https://8080-1234abcd-abcd-1234-abcd-1234abcd.europe-west1.cloudshell.dev/?authuser=0

Is there a way to determine what this URL is going to be from the terminal, without having to click on the "web preview" button?

Note: For those wondering what the use case for this is. I am using the SSH cloud shell access feature that allows you to remote into your cloud shell instance via SSH from any terminal emulator. Unfortunately, doing so means that you no longer have access to the "web preview" button (as you are using your own terminal and not the web based one) and so are unable to know what the URL for your web preview is going to be located.


Solution

  • You can determine what the URL will be from the terminal with the environment variable WEB_HOST, which is preconfigured in Cloud Shell.

    The formatted preview URL will look like this:
    https://$PORT-$WEB_HOST

    See Preview web apps Docs