package main import ( "log" "net/http" "synlotto-website/bootstrap" "synlotto-website/config" "synlotto-website/handlers" "synlotto-website/helpers" "synlotto-website/logging" "synlotto-website/middleware" "synlotto-website/models" "synlotto-website/routes" "synlotto-website/storage" "github.com/gorilla/csrf" ) func main() { appState, err := bootstrap.LoadAppState("config/config.json") if err != nil { logging.Error("Failed to load app state: %v", err) } config.Init(appState.Config) logging.LogConfig(appState.Config) db := storage.InitDB("synlotto.db") models.SetDB(db) // Should be in storage not models. csrfMiddleware := csrf.Protect( []byte("abcdefghijklmnopqrstuvwx12345678"), // TodO: Make Global csrf.Secure(true), csrf.Path("/"), ) mux := http.NewServeMux() routes.SetupAdminRoutes(mux, db) routes.SetupAccountRoutes(mux, db) routes.SetupResultRoutes(mux, db) routes.SetupSyndicateRoutes(mux, db) mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) mux.HandleFunc("/", handlers.Home(db)) wrapped := helpers.RateLimit(csrfMiddleware(mux)) wrapped = middleware.EnforceHTTPS(wrapped, appState.Config.HttpServer.ProductionMode) wrapped = middleware.SecureHeaders(wrapped) wrapped = middleware.Recover(wrapped) log.Println("🌐 Running on http://localhost:8080") http.ListenAndServe(":8080", wrapped) }