Skip to content

Commit

Permalink
Get port from PORT env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Erdmann committed Nov 25, 2020
1 parent b92d8d9 commit 8b83ef7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
)

func main() {
Expand All @@ -23,8 +24,13 @@ func main() {

http.HandleFunc("/search", handleSearch(searcher))

log.Println("Listening on :3001...")
err = http.ListenAndServe(":3001", nil)
port := os.Getenv("PORT")
if port == "" {
port = "3001"
}

fmt.Printf("Listening on port %s...", port)
err = http.ListenAndServe(fmt.Sprintf(":%s", port), nil)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 8b83ef7

Please sign in to comment.