forked from TF2Stadium/Helen
/
main.go
61 lines (50 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
package main
import (
"net/http"
"time"
"gopkg.in/tylerb/graceful.v1"
"github.com/TF2Stadium/Helen/config"
"github.com/TF2Stadium/Helen/config/stores"
"github.com/TF2Stadium/Helen/controllers/socket"
"github.com/TF2Stadium/Helen/database"
"github.com/TF2Stadium/Helen/database/migrations"
"github.com/TF2Stadium/Helen/helpers"
"github.com/TF2Stadium/Helen/models"
"github.com/TF2Stadium/Helen/routes"
"github.com/googollee/go-socket.io"
"github.com/gorilla/mux"
"github.com/rs/cors"
)
func main() {
helpers.InitLogger()
config.SetupConstants()
database.Init()
migrations.Do()
stores.SetupStores()
models.InitServerConfigs()
// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)
helpers.Logger.Debug("Starting the server")
r := mux.NewRouter()
// init http server
routes.SetupHTTPRoutes(r)
http.Handle("/", r)
// init socket.io server
socketServer, err := socketio.NewServer(nil)
if err != nil {
helpers.Logger.Fatal(err.Error())
}
socket.InitBroadcaster(socketServer)
routes.SetupSocketRoutes(socketServer)
r.Handle("/socket.io/", socketServer)
// init static FileServer
// TODO be careful to set this to correct location when deploying
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/",
http.FileServer(http.Dir(config.Constants.StaticFileLocation))))
corsHandler := cors.New(cors.Options{
AllowedOrigins: config.Constants.AllowedCorsOrigins,
AllowCredentials: true,
}).Handler(r)
// start the server
helpers.Logger.Debug("Serving at localhost:" + config.Constants.Port + "...")
graceful.Run(":"+config.Constants.Port, 10*time.Second, corsHandler)
}