Skip to content

Instantly share code, notes, and snippets.

@khalidx
Created May 8, 2025 04:21
Show Gist options
  • Save khalidx/fabfa3b5ab87808f65ed6a1bd8085a95 to your computer and use it in GitHub Desktop.
Save khalidx/fabfa3b5ab87808f65ed6a1bd8085a95 to your computer and use it in GitHub Desktop.
How to build the URL that a GitHub Codespace will use for a port.

Tip

In a Codespace, we have access to the CODESPACE_NAME and the GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN environment variables.

We can use these variables to build the corresponding URL that will be used when forwarding a port in GitHub Codespaces.

Here's how we can build the URL for the forwarded port 80:

export X_PORT='80'
export X_CODESPACE_URL="https://${CODESPACE_NAME}-${X_PORT}.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}"

echo "${X_CODESPACE_URL}"

In the future, GitHub Codespaces may support this natively (I hope).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment