fix(session): conditionally bind handler and log errors
This commit is contained in:
parent
2c7aea4654
commit
f8db96c717
@ -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,
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user