An experimental IndieWeb site built in Go.

use environment variables for all server config

Changed files
+29 -8
+11
.env.example
··· 1 + # Port for the server to listen on. 2 + # Change this to something you can tunnel during local development 3 + PORT=5050 4 + 5 + # Root URL, with protocol, where your server is accessible. 6 + PROFILE_URL="http://localhost/" 7 + 8 + ADMIN_USERNAME="change" 9 + ADMIN_PASSWORD="me" 10 + 11 + JWT_SECRET="bogus"
+18 -8
main.go
··· 2 2 3 3 import ( 4 4 "encoding/json" 5 - "flag" 5 + "os" 6 6 "time" 7 7 8 8 "log" ··· 26 26 ) 27 27 28 28 func main() { 29 - // Setup flags. 30 - portPtr := flag.Int("port", 80, "port to listen on") 31 - addressPtr := flag.String("profile", "http://localhost/", "client URL and front facing address to listen on") 32 - flag.Parse() 29 + var port int 30 + if portStr, ok := os.LookupEnv("PORT"); !ok { 31 + port = 80 32 + } else { 33 + portInt, err := strconv.Atoi(portStr) 34 + if err != nil { 35 + log.Fatal(err) 36 + } 33 37 34 - profileURL := *addressPtr 38 + port = portInt 39 + } 40 + 41 + profileURL, ok := os.LookupEnv("PROFILE_URL") 42 + if !ok { 43 + profileURL = "http://localhost/" 44 + } 35 45 36 46 // Validate the given Client ID before starting the HTTP server. 37 47 err := indieauth.IsValidProfileURL(profileURL) ··· 84 94 }) 85 95 86 96 // Start it! 87 - log.Printf("Listening on http://localhost:%d", *portPtr) 97 + log.Printf("Listening on http://localhost:%d", port) 88 98 log.Printf("Listening on %s", profileURL) 89 - if err := http.ListenAndServe(":"+strconv.Itoa(*portPtr), r); err != nil { 99 + if err := http.ListenAndServe(":"+strconv.Itoa(port), r); err != nil { 90 100 log.Fatal(err) 91 101 } 92 102 }