Skip to content

Commit

Permalink
Merge pull request #7 from nregina-hbs/listen-port
Browse files Browse the repository at this point in the history
Allow selection of listen port
  • Loading branch information
sktan authored Apr 1, 2023
2 parents bf078b6 + 7a1fcf7 commit b957d7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Configuration is done via Environment Variables:
| CODEARTIFACT_DOMAIN | Yes | Your CodeArtifact Domain (e.g. sktansandbox) |
| CODEARTIFACT_TYPE | No | Use one of the following: pypi, npm, maven, nuget |
| CODEARTIFACT_OWNER | No | The AWS Account Id of the CodeArtifact Owner (if it's your own account, it can be empty) |
| LISTEN_PORT | No | Port on which the proxy should listen. Defaults to 8080 |

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

Expand Down
13 changes: 12 additions & 1 deletion src/tools/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -125,13 +126,23 @@ func ProxyInit() {
panic(err)
}

// Get port from LISTEN_PORT environment variable. If not set, default to 8080.
port := getEnv("LISTEN_PORT", "8080")

proxy := httputil.NewSingleHostReverseProxy(remote)

proxy.ModifyResponse = ProxyResponseHandler()

http.HandleFunc("/", ProxyRequestHandler(proxy))
err = http.ListenAndServe(":8080", nil)
err = http.ListenAndServe(":"+port, nil)
if err != nil {
panic(err)
}
}

func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}

0 comments on commit b957d7d

Please sign in to comment.