Skip to content

Commit

Permalink
Added ability to bind to custom port
Browse files Browse the repository at this point in the history
  • Loading branch information
owais committed May 9, 2018
1 parent e1f45c8 commit c9841bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 9 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func main() {

var slackToken string
var port string

app := cli.NewApp()
app.Name = "RTTD"
Expand All @@ -27,6 +28,13 @@ func main() {
Destination: &slackToken,
EnvVar: "SLACK_API_TOKEN",
},
cli.StringFlag{
Name: "port",
Usage: "PORT to start web server on",
Destination: &port,
EnvVar: "PORT",
Value: "5000",
},
}

app.Action = func(c *cli.Context) error {
Expand All @@ -35,7 +43,7 @@ func main() {
}
endpoint := "https://slack.com/api/users.list?token=" + slackToken
team := slack.NewTeam(endpoint)
http.Start(team)
http.Start(team, port)
return nil

}
Expand Down
6 changes: 1 addition & 5 deletions pkg/api/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import (
_ "github.com/owais/RTTD/static" // bundle assets
)

var port string
var slackToken string

type handler func(t teams.Team, w http.ResponseWriter, r *http.Request)

func withTeams(team teams.Team, f handler) http.HandlerFunc {
Expand Down Expand Up @@ -69,13 +66,12 @@ func fetchFromSlack(t teams.Team, w http.ResponseWriter, r *http.Request) {
w.Write(contents)
}

func Start(team teams.Team) {
func Start(team teams.Team, port string) {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(parcello.Root("/"))))

http.HandleFunc("/api/slack/fetch/", withTeams(team, fetchFromSlack))
http.HandleFunc("/", withTeams(team, indexHandler))

port = "5000"
fmt.Println("Starting server on port " + port)
http.ListenAndServe(":"+port, nil)
}

0 comments on commit c9841bf

Please sign in to comment.