diff --git a/scripts/develop/main.go b/scripts/develop/main.go index 4973029b23..0e28292dba 100644 --- a/scripts/develop/main.go +++ b/scripts/develop/main.go @@ -42,6 +42,7 @@ const ( defaultAPIPort = "3000" defaultWebPort = "8080" defaultProxyPort = "3010" + defaultAccessURL = "http://127.0.0.1:%d" defaultPassword = "SomeSecurePassword!" defaultStarterTemplate = "docker" healthTimeout = 60 * time.Second @@ -85,7 +86,8 @@ func main() { { Flag: "access-url", Env: "CODER_DEV_ACCESS_URL", - Description: "Override access URL.", + Default: defaultAccessURL, + Description: "Override access URL. The %d placeholder will be replaced with the API port. Set to empty to enable devtunnel (pit-1.try.coder.app).", Value: serpent.StringOf(&cfg.accessURL), }, { @@ -192,8 +194,8 @@ func (c *devConfig) validate() error { // resolveEnv sets defaults, unsets leaked credentials, resolves // filesystem paths, and computes the child process environment. func (c *devConfig) resolveEnv() error { - if c.accessURL == "" { - c.accessURL = fmt.Sprintf("http://127.0.0.1:%d", c.apiPort) + if strings.Contains(c.accessURL, "%d") { + c.accessURL = fmt.Sprintf(c.accessURL, c.apiPort) } // Prevent inherited credentials from leaking into child diff --git a/scripts/develop/main_test.go b/scripts/develop/main_test.go index 1594d2806a..e178dda6a7 100644 --- a/scripts/develop/main_test.go +++ b/scripts/develop/main_test.go @@ -289,7 +289,7 @@ func TestDevConfigResolveEnv(t *testing.T) { t.Setenv("CODER_SESSION_TOKEN", "leaked") t.Setenv("CODER_URL", "https://leaked.example.com") - cfg := &devConfig{apiPort: 3000} + cfg := &devConfig{apiPort: 3000, accessURL: defaultAccessURL} require.NoError(t, cfg.resolveEnv()) wd, _ := os.Getwd()