Skip to content

Commit b957d7d

Browse files
authored
Merge pull request #7 from nregina-hbs/listen-port
Allow selection of listen port
2 parents bf078b6 + 7a1fcf7 commit b957d7d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Configuration is done via Environment Variables:
3737
| CODEARTIFACT_DOMAIN | Yes | Your CodeArtifact Domain (e.g. sktansandbox) |
3838
| CODEARTIFACT_TYPE | No | Use one of the following: pypi, npm, maven, nuget |
3939
| CODEARTIFACT_OWNER | No | The AWS Account Id of the CodeArtifact Owner (if it's your own account, it can be empty) |
40+
| LISTEN_PORT | No | Port on which the proxy should listen. Defaults to 8080 |
4041

4142
By default, the proxy will choose to use the Pypi as it's type.
4243

src/tools/proxy.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"net/http/httputil"
1111
"net/url"
12+
"os"
1213
"strconv"
1314
"strings"
1415
"sync"
@@ -125,13 +126,23 @@ func ProxyInit() {
125126
panic(err)
126127
}
127128

129+
// Get port from LISTEN_PORT environment variable. If not set, default to 8080.
130+
port := getEnv("LISTEN_PORT", "8080")
131+
128132
proxy := httputil.NewSingleHostReverseProxy(remote)
129133

130134
proxy.ModifyResponse = ProxyResponseHandler()
131135

132136
http.HandleFunc("/", ProxyRequestHandler(proxy))
133-
err = http.ListenAndServe(":8080", nil)
137+
err = http.ListenAndServe(":"+port, nil)
134138
if err != nil {
135139
panic(err)
136140
}
137141
}
142+
143+
func getEnv(key, fallback string) string {
144+
if value, ok := os.LookupEnv(key); ok {
145+
return value
146+
}
147+
return fallback
148+
}

0 commit comments

Comments
 (0)