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).