Skip to content

Commit

Permalink
Merge pull request #64 from tslocum/https_port
Browse files Browse the repository at this point in the history
Add ServerConfig.HttpsPort
  • Loading branch information
cjslep authored Apr 26, 2021
2 parents 25767eb + f5c3221 commit 6cc6684
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func defaultConfig(dbkind string) (c *config.Config, err error) {

func defaultServerConfig() config.ServerConfig {
return config.ServerConfig{
HttpsPort: 443,
CookieMaxAge: 86400,
SaltSize: 32,
BCryptStrength: bcrypt.DefaultCost,
Expand Down
1 change: 1 addition & 0 deletions framework/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Config struct {
// Configuration section specifically for the HTTP server.
type ServerConfig struct {
Host string `ini:"sr_host" comment:"(required) Host with TLD for this instance (basically, the fully qualified domain or subdomain); ignored in debug mode"`
HttpsPort int `ini:"sr_https_port" comment:"(default: 443) Port to serve HTTPS requests on"`
CertFile string `ini:"sr_cert_file" comment:"(required) Path to the certificate file used to establish TLS connections for HTTPS"`
KeyFile string `ini:"sr_key_file" comment:"(required) Path to the private key file used to establish TLS connections for HTTPS"`
CookieAuthKeyFile string `ini:"sr_cookie_auth_key_file" comment:"(required) Path to private key file used for cookie authentication"`
Expand Down
3 changes: 3 additions & 0 deletions framework/config/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (c *ServerConfig) Verify() error {
if len(c.Host) == 0 {
return errors.New("sr_host is empty, but it is required")
}
if c.HttpsPort == 0 {
return errors.New("sr_https_port is empty, but it is required")
}
if len(c.CertFile) == 0 {
return errors.New("sr_cert_file is empty, but it is required")
}
Expand Down
5 changes: 5 additions & 0 deletions framework/prompt_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Let's go!`)))
if err != nil {
return
}
c.ServerConfig.HttpsPort, err = promptIntWithDefault(
"Enter the port to serve HTTPS requests on", 443)
if err != nil {
return
}
c.ServerConfig.CertFile, err = promptString(
"Enter the path to the file containing the certificate used in HTTPS connections")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion framework/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewHTTPSServer(c *config.Config, h http.Handler, a app.Application, sqldb *
// Prepare HTTPS server. No option to run the server as HTTP in prod,
// because we're living in the future.
httpsServer := &http.Server{
Addr: ":https",
Addr: fmt.Sprintf(":%d", c.ServerConfig.HttpsPort),
Handler: h,
ReadTimeout: time.Duration(c.ServerConfig.HttpsReadTimeoutSeconds) * time.Second,
WriteTimeout: time.Duration(c.ServerConfig.HttpsWriteTimeoutSeconds) * time.Second,
Expand Down

0 comments on commit 6cc6684

Please sign in to comment.