Production state
This commit is contained in:
+12
-1
@@ -2,6 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func LoadConfigFromEnv() (Config, error) {
|
||||
values := []struct {
|
||||
target *time.Duration
|
||||
key, fallback string
|
||||
}{{&c.ReadHeaderTimeout, "HTTP_READ_HEADER_TIMEOUT", "5s"}, {&c.ReadTimeout, "HTTP_READ_TIMEOUT", "30s"}, {&c.WriteTimeout, "HTTP_WRITE_TIMEOUT", "30s"}, {&c.IdleTimeout, "HTTP_IDLE_TIMEOUT", "60s"}, {&c.ShutdownTimeout, "HTTP_SHUTDOWN_TIMEOUT", "10s"}}
|
||||
}{{&c.ReadHeaderTimeout, "HTTP_READ_HEADER_TIMEOUT", "5s"}, {&c.ReadTimeout, "HTTP_READ_TIMEOUT", "30s"}, {&c.WriteTimeout, "HTTP_WRITE_TIMEOUT", "10m"}, {&c.IdleTimeout, "HTTP_IDLE_TIMEOUT", "60s"}, {&c.ShutdownTimeout, "HTTP_SHUTDOWN_TIMEOUT", "10s"}}
|
||||
for _, value := range values {
|
||||
*value.target, err = duration(value.key, value.fallback)
|
||||
if err != nil {
|
||||
@@ -31,6 +32,16 @@ func LoadConfigFromEnv() (Config, error) {
|
||||
if c.StudentPIN == "" || c.InstructorPIN == "" || len(c.SessionSecret) < 32 || c.PublicBaseURL == "" {
|
||||
return c, errors.New("STUDENT_PIN, INSTRUCTOR_PIN, PUBLIC_BASE_URL, and a 32+ character SESSION_SIGNING_SECRET are required")
|
||||
}
|
||||
if c.LogFormat != "text" && c.LogFormat != "json" {
|
||||
return c, errors.New("LOG_FORMAT must be text or json")
|
||||
}
|
||||
publicURL, err := url.Parse(c.PublicBaseURL)
|
||||
if err != nil || publicURL.Host == "" || (publicURL.Scheme != "http" && publicURL.Scheme != "https") || (publicURL.Path != "" && publicURL.Path != "/") || publicURL.RawQuery != "" || publicURL.Fragment != "" || publicURL.User != nil {
|
||||
return c, errors.New("PUBLIC_BASE_URL must be an HTTP(S) origin without a path, query, credentials, or fragment")
|
||||
}
|
||||
if c.Environment == "production" && publicURL.Scheme != "https" {
|
||||
return c, errors.New("PUBLIC_BASE_URL must use HTTPS in production")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
func get(k, d string) string {
|
||||
|
||||
Reference in New Issue
Block a user