Skip to content

Commit c9841bf

Browse files
committed
Added ability to bind to custom port
1 parent e1f45c8 commit c9841bf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

cmd/server/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func main() {
1515

1616
var slackToken string
17+
var port string
1718

1819
app := cli.NewApp()
1920
app.Name = "RTTD"
@@ -27,6 +28,13 @@ func main() {
2728
Destination: &slackToken,
2829
EnvVar: "SLACK_API_TOKEN",
2930
},
31+
cli.StringFlag{
32+
Name: "port",
33+
Usage: "PORT to start web server on",
34+
Destination: &port,
35+
EnvVar: "PORT",
36+
Value: "5000",
37+
},
3038
}
3139

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

4149
}

pkg/api/http/handlers.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import (
1414
_ "github.com/owais/RTTD/static" // bundle assets
1515
)
1616

17-
var port string
18-
var slackToken string
19-
2017
type handler func(t teams.Team, w http.ResponseWriter, r *http.Request)
2118

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

72-
func Start(team teams.Team) {
69+
func Start(team teams.Team, port string) {
7370
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(parcello.Root("/"))))
7471

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

78-
port = "5000"
7975
fmt.Println("Starting server on port " + port)
8076
http.ListenAndServe(":"+port, nil)
8177
}

0 commit comments

Comments
 (0)