fix: изменение монтирования /ws
CI / Go (build + vet + test) (push) Canceled after 0s
CI / Web (build + lint) (push) Canceled after 0s

This commit is contained in:
vantablackTea
2026-09-27 20:35:20 +03:00
parent f381b4cd14
commit ae24bdd0e0
3 changed files with 36 additions and 4 deletions
+13 -1
View File
@@ -3,6 +3,7 @@ package api
import (
"log/slog"
"net/http"
"strings"
"messenger/internal/auth"
"messenger/internal/platform/config"
@@ -19,7 +20,8 @@ type apiHandler struct {
}
// NewHandler builds the /api/v1 route tree with all middleware applied.
func NewHandler(st *store.Store, tm *auth.TokenManager, hub *realtime.Hub, log *slog.Logger, cfg *config.Config) http.Handler {
// static, when non-nil, serves the built frontend for non-API paths.
func NewHandler(st *store.Store, tm *auth.TokenManager, hub *realtime.Hub, log *slog.Logger, cfg *config.Config, static http.Handler) http.Handler {
h := &apiHandler{
store: st,
tokens: tm,
@@ -54,6 +56,16 @@ func NewHandler(st *store.Store, tm *auth.TokenManager, hub *realtime.Hub, log *
mux.Handle("GET /ws", authHandler)
if static != nil {
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/api/") {
writeError(w, http.StatusNotFound, "not found")
return
}
static.ServeHTTP(w, r)
})
}
return mux
}