Example #1
0
File: main.go Project: N1xx1/Helen
func main() {
	authority.RegisterTypes()
	helpers.InitLogger()
	helpers.InitAuthorization()
	config.SetupConstants()
	database.Init()
	migrations.Do()
	stores.SetupStores()
	models.PaulingConnect()
	go models.ReadyTimeoutListener()
	StartListener()
	chelpers.CheckLogger()
	if config.Constants.SteamIDWhitelist != "" {
		chelpers.InitSteamIDWhitelist(config.Constants.SteamIDWhitelist)
	}
	// lobby := models.NewLobby("cp_badlands", 10, "a", "a", 1)
	helpers.Logger.Debug("Starting the server")

	// init http server
	routes.SetupHTTPRoutes()

	// init socket.io server
	socketServer, err := socketio.NewServer(nil)
	if err != nil {
		helpers.Logger.Fatal(err.Error())
	}
	broadcaster.Init(socketServer)
	defer broadcaster.Stop()
	routes.SetupSocketRoutes(socketServer)
	http.Handle("/socket.io/", socketServer)

	// init static FileServer
	// TODO be careful to set this to correct location when deploying
	http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, r.URL.Path[1:])
	})
	corsHandler := cors.New(cors.Options{
		AllowedOrigins:   config.Constants.AllowedCorsOrigins,
		AllowCredentials: true,
	}).Handler(http.DefaultServeMux)

	// start the server
	helpers.Logger.Debug("Serving at localhost:" + config.Constants.Port + "...")
	graceful.Run(":"+config.Constants.Port, 10*time.Second, corsHandler)
}
Example #2
0
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)
}