Skip to content

Commit

Permalink
Merge branch 'master' into chore/adds-watcherr
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoliveira committed Jun 15, 2024
2 parents c7d293f + 66e00b0 commit 6b33a2b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .ergo
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ two.domain http://localhost:8082
redislocal redis://localhost:6543
*.wildcard http://localhost:3030
withextraspace http://localhost:2222
127.0.0.1:3034 mysitewithip
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.2
v0.4.2
4 changes: 4 additions & 0 deletions proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func readServicesFromFile(filepath string) ([]Service, error) {
name, urlWithPort = pair[0], pair[1]
}

if !strings.Contains(urlWithPort, "://") {
urlWithPort = "http://" + urlWithPort
}

service, err := NewService(name, urlWithPort)
if err != nil {
return nil, fmt.Errorf("invalid service format `%v`. %v`", line, err)
Expand Down
2 changes: 1 addition & 1 deletion proxy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestWhenHasErgoFile(t *testing.T) {
})

t.Run("It loads the services redirections", func(t *testing.T) {
expected := 10
expected := 11
service := len(config.Services)

if expected != service {
Expand Down
6 changes: 5 additions & 1 deletion proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ func NewService(name string, rawURL string) (Service, error) {
}

url, err := url.ParseRequestURI(rawURL)
if err != nil {
return Service{}, fmt.Errorf("Error parsing URL '%v': %v", rawURL, err)
}

isInvalidHostname := len(url.Hostname()) == 0 || strings.Contains(url.Hostname(), ":")
if err != nil || isInvalidHostname {
if isInvalidHostname {
return Service{}, fmt.Errorf("URL '%v' is invalid, example of valid URL 'http://example.com:8080'", rawURL)
}

Expand Down
6 changes: 6 additions & 0 deletions proxy/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func TestNewService(t *testing.T) {
serviceURL: "http://localhost:8080",
expectError: true,
},
{
title: "a service containing an invalid URL is invalid",
serviceName: "ergoproxy",
serviceURL: "http:///localhost:3000\n",
expectError: true,
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 6b33a2b

Please sign in to comment.