Skip to content

Commit

Permalink
feat: Add tls support
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Mar 5, 2024
1 parent d7767e0 commit 5307aa0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ You can also enable the caching functionality to speed things up.`,
r.Mount("/", apiRouter)

log.Log.Infof("Listen on %s:%d", config.Bind, config.Port)
log.Log.Panic(http.ListenAndServe(fmt.Sprintf("%s:%d", config.Bind, config.Port), r))
if config.TlsKeyPath != "" && config.TlsCertPath != "" {
log.Log.Panic(http.ListenAndServeTLS(fmt.Sprintf("%s:%d", config.Bind, config.Port), config.TlsCertPath, config.TlsKeyPath, r))
} else {
log.Log.Panic(http.ListenAndServe(fmt.Sprintf("%s:%d", config.Bind, config.Port), r))
}
} else {
log.Log.Panicf("%s version not supported", config.ApiVersion)
}
Expand All @@ -162,6 +166,8 @@ func init() {
serveCmd.Flags().StringVar(&config.CacheDir, "cachedir", "/var/cache/gorge", "cache directory")
serveCmd.Flags().StringVar(&config.CachePrefixes, "cache-prefixes", "/v3/files", "url prefixes to cache")
serveCmd.Flags().StringVar(&config.JwtSecret, "jwt-secret", "changeme", "jwt secret")
serveCmd.Flags().StringVar(&config.TlsCertPath, "tls-cert", "", "path to tls cert file")
serveCmd.Flags().StringVar(&config.TlsKeyPath, "tls-key", "", "path to tls key file")
serveCmd.Flags().Int64Var(&config.CacheMaxAge, "cache-max-age", 86400, "max number of seconds responses should be cached")
serveCmd.Flags().BoolVar(&config.NoCache, "no-cache", false, "disables the caching functionality")
serveCmd.Flags().BoolVar(&config.ImportProxiedReleases, "import-proxied-releases", false, "add every proxied modules to local store")
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ var (
CacheMaxAge int64
ImportProxiedReleases bool
JwtSecret string
TlsCertPath string
TlsKeyPath string
)

0 comments on commit 5307aa0

Please sign in to comment.