Skip to content

Commit

Permalink
Merge pull request #489 from tucksaun/fix/open-local-wildcard
Browse files Browse the repository at this point in the history
Don't try to use a wildcard domain in `open:local`
  • Loading branch information
fabpot committed Jun 14, 2024
2 parents 7c0b22e + 89b3310 commit 570fd66
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commands/openers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var projectLocalOpenCmd = &console.Command{
}
host := fmt.Sprintf("127.0.0.1:%d", pidFile.Port)
if proxyConf, err := proxy.Load(util.GetHomeDir()); err == nil {
domains := proxyConf.GetDomains(projectDir)
domains := proxyConf.GetReachableDomains(projectDir)
if len(domains) > 0 {
host = domains[0]
}
Expand Down
17 changes: 17 additions & 0 deletions local/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ func (c *Config) GetDomains(dir string) []string {
return domains
}

func (c *Config) GetReachableDomains(dir string) []string {
c.mu.Lock()
defer c.mu.Unlock()
domains := []string{}
for domain, d := range c.domains {
// domain is defined using a wildcard: we don't know the exact domain,
// so we can't use it directly as-is to reach the project
if strings.Contains(domain, "*") {
continue
}
if d == dir {
domains = append(domains, domain+"."+c.TLD)
}
}
return domains
}

func (c *Config) SetDomains(domains map[string]string) {
c.mu.Lock()
c.domains = domains
Expand Down
13 changes: 13 additions & 0 deletions local/proxy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ func (s *ProxySuite) TestGetDir(c *C) {
c.Assert(p.GetDir("foo.symfony.com"), Equals, "any_symfony_com")
c.Assert(p.GetDir("foo.live.symfony.com"), Equals, "any_live_symfony_com")
}

func (s *ProxySuite) TestGetReachableDomains(c *C) {
p := &Config{
TLD: "wip",
domains: map[string]string{
"*.symfony": "symfony_com",
"symfony": "symfony_com",
"custom.*.symfony": "symfony_com",
"*.live.symfony": "symfony_com",
},
}
c.Assert(p.GetReachableDomains("symfony_com"), DeepEquals, []string{"symfony.wip"})
}

0 comments on commit 570fd66

Please sign in to comment.