Files
website/main.go

45 lines
1.1 KiB
Go

package main
import (
"log"
"net/http"
"synlotto-website/handlers"
"synlotto-website/helpers"
"synlotto-website/middleware"
"synlotto-website/models"
"synlotto-website/routes"
"synlotto-website/storage"
"github.com/gorilla/csrf"
)
func main() {
db := storage.InitDB("synlotto.db")
models.SetDB(db) // Should be in storage not models.
var isProduction = false
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, isProduction)
wrapped = middleware.SecureHeaders(wrapped)
wrapped = middleware.Recover(wrapped)
log.Println("🌐 Running on http://localhost:8080")
http.ListenAndServe(":8080", wrapped)
}