From e743e8d1c5d0cfddb7e7a42d7cfe512811d04873 Mon Sep 17 00:00:00 2001 From: Christopher Denny Date: Sun, 1 May 2022 21:56:43 -0700 Subject: [PATCH] Set up autocert https --- README.md | 2 +- get_teams.go | 4 ++-- go.mod | 1 + go.sum | 11 +++++++++++ main.go | 24 +++++++++++++++++------- tmpl/base.html | 2 +- tmpl/index.html | 2 +- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 69ba405..7be64a3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # lastwin -[lastwin.info](http://lastwin.info) +[lastwin.info](https://lastwin.info) diff --git a/get_teams.go b/get_teams.go index 1bad9e7..0e336f4 100644 --- a/get_teams.go +++ b/get_teams.go @@ -8,8 +8,8 @@ import ( ) var ( - cfbTeamsURL = "http://www.espn.com/college-football/teams" - nflTeamsURL = "http://www.espn.com/nfl/teams" + cfbTeamsURL = "https://www.espn.com/college-football/teams" + nflTeamsURL = "https://www.espn.com/nfl/teams" ) // Team is a struct storing team name and id diff --git a/go.mod b/go.mod index bdad81b..bd2f7ed 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ go 1.12 require ( github.com/gorilla/mux v1.7.3 github.com/sahilm/fuzzy v0.1.0 + golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect ) diff --git a/go.sum b/go.sum index cc4cdf5..d68072f 100644 --- a/go.sum +++ b/go.sum @@ -2,3 +2,14 @@ github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f h1:OeJjE6G4dgCY4PIXvIRQbE8+RX+uXZyGhUy/ksMGJoc= +golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go index a26fbbb..9b53d8b 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "time" "github.com/gorilla/mux" + "golang.org/x/crypto/acme/autocert" ) var ( @@ -23,14 +24,14 @@ var ( urls = map[string]map[string]string{ "cfb": { - "query": "http://www.espn.com/college-football/team/schedule/_/id/%s/season/%s", - "espn": "http://www.espn.com/college-football/team/_/id/%s", - "img": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/%s.png", + "query": "https://www.espn.com/college-football/team/schedule/_/id/%s/season/%s", + "espn": "https://www.espn.com/college-football/team/_/id/%s", + "img": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/ncaa/500/%s.png", }, "nfl": { "query": "https://www.espn.com/nfl/team/schedule/_/name/%s/season/%s", - "espn": "http://www.espn.com/nfl/team/_/id/%s", - "img": "http://a.espncdn.com/combiner/i?img=/i/teamlogos/nfl/500/%s.png", + "espn": "https://www.espn.com/nfl/team/_/id/%s", + "img": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/nfl/500/%s.png", }, } ) @@ -159,6 +160,15 @@ func main() { fileServer := Gzip(http.FileServer(http.Dir("static/"))) r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fileServer)) - log.Printf("Starting server on port %s", port) - log.Fatal(http.ListenAndServe(":"+port, r)) + m := &autocert.Manager{ + Cache: autocert.DirCache("."), + Prompt: autocert.AcceptTOS, + HostPolicy: autocert.HostWhitelist("www.lastwin.info", "lastwin.info"), + } + s := &http.Server{ + Addr: ":https", + TLSConfig: m.TLSConfig(), + Handler: r, + } + log.Fatal(s.ListenAndServeTLS("", "")) } diff --git a/tmpl/base.html b/tmpl/base.html index 1a03e18..14d3016 100644 --- a/tmpl/base.html +++ b/tmpl/base.html @@ -18,7 +18,7 @@ - + diff --git a/tmpl/index.html b/tmpl/index.html index 6b67e33..4ff6cf5 100644 --- a/tmpl/index.html +++ b/tmpl/index.html @@ -6,7 +6,7 @@ When did your football team last win? {{ end }} {{ define "image" }} - http://lastwin.info/static/football.png + https://lastwin.info/static/football.png {{ end }} {{ define "content" }}