-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
48 lines (34 loc) · 1 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/virgild/signalmon/templates"
"goji.io"
"goji.io/pat"
)
// port := flag.Int("p", 8000, "Listen port number")
// flag.Parse()
// fmt.Fprint(os.Stdout, fmt.Sprintf("Phleeeeeep running at port %v:\n", *port))
// listenStr := fmt.Sprintf(":%v", *port)
// mux := goji.NewMux()
// mux.HandleFuncC(pat.Get("/t"), t)
// loggedMux := handlers.LoggingHandler(os.Stdout, mux)
// go runFetcher()
// startFetch()
// http.ListenAndServe(listenStr, loggedMux)
func StartServer(port int) {
listenStr := fmt.Sprintf(":%d", port)
mux := goji.NewMux()
mux.HandleFunc(pat.Get("/bundle.js"), jsBundle)
mux.HandleFunc(pat.Get("/"), indexPage)
loggedMux := handlers.LoggingHandler(os.Stdout, mux)
http.ListenAndServe(listenStr, loggedMux)
}
func indexPage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, templates.IndexHtml)
}
func jsBundle(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./assets/bundle.js")
}