diff --git a/internal/server.go b/internal/server.go index f9700e6..8506fb5 100644 --- a/internal/server.go +++ b/internal/server.go @@ -20,7 +20,6 @@ import ( "context" "net" "net/http" - "path" "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus" @@ -95,9 +94,15 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) { public.Use( session.Middleware( session.Exclusions(exclusions...), - session.JavaScriptPath(path.Join(config.Session.Prefix, "pages.js")), + session.JavaScriptPath("/pages.js"), ), ) + + var handler http.Handler = session.Handler() + handler = http.StripPrefix(config.Session.Prefix, handler) + + public.Handle("/pages.js", web.Handler()).Methods(http.MethodGet) + public.PathPrefix(config.Session.Prefix).Handler(handler) } admin := public.PathPrefix(config.Admin.Prefix).Subrouter() @@ -111,15 +116,6 @@ func NewServer(ctx context.Context, config ServerConfig) (*Server, error) { }) } - { - var handler http.Handler = session.Handler() - handler = http.StripPrefix(config.Session.Prefix, handler) - - session := public.PathPrefix(config.Session.Prefix).Subrouter() - session.HandleFunc("/pages.js", web.Handler()).Methods(http.MethodGet) - session.Handle("/", handler) - } - return &Server{ AdminMux: admin, diff --git a/internal/session/handler.go b/internal/session/handler.go index 6b040b7..e2921b7 100644 --- a/internal/session/handler.go +++ b/internal/session/handler.go @@ -21,7 +21,9 @@ import ( "time" "github.com/gorilla/websocket" + "go.uber.org/zap" + "github.com/mjpitz/myago/zaputil" "github.com/mjpitz/pages/internal/geoip" "github.com/mjpitz/pages/internal/metrics" ) @@ -45,9 +47,11 @@ type Handle struct { } func (h *Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) { + log := zaputil.Extract(r.Context()) + conn, err := h.upgrader.Upgrade(w, r, nil) if err != nil { - // log + log.Error("failed to upgrade connection", zap.Error(err)) return } @@ -70,7 +74,6 @@ func (h *Handle) ServeHTTP(w http.ResponseWriter, r *http.Request) { err = conn.ReadJSON(&req) if err != nil { - // log return } }