i'm getting...something...in the cookie now

This commit is contained in:
2026-05-22 16:38:44 -06:00
parent 50546ae4d4
commit 095b35f410
+26 -15
View File
@@ -7,15 +7,13 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/alexedwards/scs/v2"
"github.com/joho/godotenv" "github.com/joho/godotenv"
) )
func handler(writer http.ResponseWriter, request *http.Request) { var sessionManager *scs.SessionManager
templ := template.Must(template.ParseFiles("./web/dist/index.html"))
templ.Execute(writer, nil)
}
func main() { func main() {
err := godotenv.Load() err := godotenv.Load()
@@ -23,20 +21,27 @@ func main() {
log.Fatal("Error loading .env file") log.Fatal("Error loading .env file")
} }
// handle authentication
sessionManager = scs.New()
sessionManager.Lifetime = 24 * time.Hour
// handle frontend views
webDir := "./web/dist" webDir := "./web/dist"
fs := http.FileServer(http.Dir(webDir)) fs := http.FileServer(http.Dir(webDir))
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { http.Handle("/", sessionManager.LoadAndSave(
if request.URL.Path != "/" { http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
path := filepath.Join(webDir, filepath.Clean(request.URL.Path)) if request.URL.Path != "/" {
_, err := os.Stat(path) path := filepath.Join(webDir, filepath.Clean(request.URL.Path))
if err == nil { _, err := os.Stat(path)
fs.ServeHTTP(writer, request) if err == nil {
return fs.ServeHTTP(writer, request)
return
}
} }
} handler(writer, request)
handler(writer, request) }),
}) ))
port := os.Getenv("HTTP_PORT") port := os.Getenv("HTTP_PORT")
if port == "" { if port == "" {
@@ -48,3 +53,9 @@ func main() {
log.Fatalf("server error: %v", err) log.Fatalf("server error: %v", err)
} }
} }
func handler(writer http.ResponseWriter, request *http.Request) {
templ := template.Must(template.ParseFiles("./web/dist/index.html"))
templ.Execute(writer, nil)
}