i'm getting...something...in the cookie now
This commit is contained in:
+18
-7
@@ -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,10 +21,16 @@ 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(
|
||||||
|
http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
if request.URL.Path != "/" {
|
if request.URL.Path != "/" {
|
||||||
path := filepath.Join(webDir, filepath.Clean(request.URL.Path))
|
path := filepath.Join(webDir, filepath.Clean(request.URL.Path))
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
@@ -36,7 +40,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user