I need to set a cookie while serving static content, html, css & js.
The code below serves a naked html file, no css etc.
All the css & js live inside an "assets" folder on the same level as index.html.
Any suggestions?
func indexHandler(w http.ResponseWriter, req *http.Request) {
http.SetCookie(w, &http.Cookie{Name: config.cookieName, Value: config.cookieValue})
cookie, err := req.Cookie(config.cookieName)
if err != nil {
log.Println(whereami.WhereAmI(), err.Error())
}
log.Println("Cookie: ", cookie)
http.StripPrefix("/", http.FileServer(http.Dir("./"))).ServeHTTP(w, req)
}
But doing this serves a complete html page:
router.PathPrefix("/").Handler(http.FileServer(http.Dir("./")))