-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (40 loc) · 1.47 KB
/
main.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
49
50
51
package main
import (
"flag"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"log"
"net/http"
"os"
"time"
)
func some(w http.ResponseWriter, req *http.Request) {
http.ServeFile(w, req, "index.html")
}
func main() {
var dir, port, host, badDevsHost string
flag.StringVar(&dir, "dir", ".", "the directory to serve files from. Defaults to the current dir")
flag.StringVar(&port, "port", "8000", "the port to bind to. Defaults to 8000")
flag.StringVar(&host, "host", "0.0.0.0", "the ip address to bind to. Defaults to 0.0.0.0")
flag.StringVar(&badDevsHost, "baddevs_host", "baddevs.io", "the domain used by server to control dns. Defaults to baddevs.io")
flag.Parse()
r := mux.NewRouter()
// Setup logs
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
srv := &http.Server{
Handler: loggedRouter,
Addr: host + ":" + port,
// Good practice: enforce timeouts for servers you create!
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
// Setup handler
badDevsHandler(r, badDevsHost)
badHandler(r)
// This will serve files under http://<host>:<port>/static/<filename>
r.PathPrefix("/assets/").Handler(http.StripPrefix("/assets/", http.FileServer(http.Dir("./client/dist/assets/"))))
r.PathPrefix("/{filename}.js").Handler(http.FileServer(http.Dir("./client/dist/")))
r.PathPrefix("/{filename}.map").Handler(http.FileServer(http.Dir("./client/dist/")))
badDevsInfo("BADdevs starting @ %v:%v\n", host, port)
log.Fatal(srv.ListenAndServe())
}