Skip to content

Commit

Permalink
feat(http): use tls keys when provided
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent 4a52c1b commit 27a5e47
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type HTTPConfig struct {
// ListenAddr is the address on which the HTTP server will listen.
ListenAddr string `env:"LISTEN_ADDR" yaml:"listen_addr"`

// TLSKeyPath is the path to the TLS private key.
TLSKeyPath string `env:"TLS_KEY_PATH" yaml:"tls_key_path"`

// TLSCertPath is the path to the TLS certificate.
TLSCertPath string `env:"TLS_CERT_PATH" yaml:"tls_cert_path"`

// PublicURL is the public URL of the HTTP server.
PublicURL string `env:"PUBLIC_URL" yaml:"public_url"`
}
Expand Down
6 changes: 6 additions & 0 deletions server/config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ http:
# The address on which the HTTP server will listen.
listen_addr: "{{ .HTTP.ListenAddr }}"
# The relative path to the TLS private key.
tls_key_path: "{{ .HTTP.TLSKeyPath }}"
# The relative path to the TLS certificate.
tls_cert_path: "{{ .HTTP.TLSCertPath }}"
# The public URL of the HTTP server.
# This is the address will be used to clone repositories.
public_url: "{{ .HTTP.PublicURL }}"
Expand Down
3 changes: 3 additions & 0 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ func (s *HTTPServer) Close() error {

// ListenAndServe starts the HTTP server.
func (s *HTTPServer) ListenAndServe() error {
if s.cfg.HTTP.TLSKeyPath != "" && s.cfg.HTTP.TLSCertPath != "" {
return s.server.ListenAndServeTLS(s.cfg.HTTP.TLSCertPath, s.cfg.HTTP.TLSKeyPath)
}
return s.server.ListenAndServe()
}

Expand Down

0 comments on commit 27a5e47

Please sign in to comment.