-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (33 loc) · 762 Bytes
/
main.go
File metadata and controls
41 lines (33 loc) · 762 Bytes
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
package main
import (
"net/http"
"os"
"server/game"
)
// Get config variables
func config(key string, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}
return value
}
func serveFiles() {
// Serve files in ./client
fs := http.FileServer(http.Dir("./client"))
http.Handle("/client/", http.StripPrefix("/client/", fs))
// Serve the index.html at /game
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "./client/index.html")
})
}
func main() {
port := config("PORT", "5000")
room := config("ROOM", "TEST")
mgr := game.NewGameManager()
mgr.SetupEndpoints()
mgr.CreateGameManually(room, nil)
serveFiles()
// Listen
http.ListenAndServe(":"+port, nil)
}