diff --git a/core/src/auth/auth.go b/core/src/auth/auth.go index 1815137..69895a7 100644 --- a/core/src/auth/auth.go +++ b/core/src/auth/auth.go @@ -1,6 +1,7 @@ package auth import ( + "bytes" "context" "encoding/base64" "encoding/json" @@ -42,7 +43,6 @@ func AuthMiddleware(next http.Handler) http.Handler { } r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodySize) - body, err := readRequestBody(r) if err != nil { if err.Error() == "http: request body too large" { @@ -53,6 +53,8 @@ func AuthMiddleware(next http.Handler) http.Handler { return } + // this is to ensure that it can be re-read by the GraphQL layer + r.Body = io.NopCloser(bytes.NewBuffer(body)) if isAllowed(r, body) { next.ServeHTTP(w, r) return diff --git a/core/src/router/file_server.go b/core/src/router/file_server.go index dd7b201..4aa7078 100644 --- a/core/src/router/file_server.go +++ b/core/src/router/file_server.go @@ -5,6 +5,8 @@ import ( "io" "io/fs" "net/http" + "path" + "strings" "github.com/clidey/whodb/core/src/log" "github.com/go-chi/chi/v5" @@ -13,32 +15,37 @@ import ( func fileServer(r chi.Router, staticFiles embed.FS) { staticFS, err := fs.Sub(staticFiles, "build") if err != nil { - log.Logger.Fatal(err) + log.Logger.Fatal("Failed to create sub filesystem:", err) } fs := http.FileServer(http.FS(staticFS)) - r.Handle("/static/*", fs) - r.Handle("/images/*", fs) - r.Handle("/asset-manifest.json", fs) - r.Handle("/manifest.json", fs) - r.Handle("/robots.txt", fs) - - r.NotFound(func(w http.ResponseWriter, r *http.Request) { - file, err := staticFS.Open("index.html") - if err != nil { - http.Error(w, "index.html not found", http.StatusInternalServerError) - return - } - defer file.Close() - - data, err := io.ReadAll(file) - if err != nil { - http.Error(w, "index.html read error", http.StatusInternalServerError) - return + r.Handle("/*", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if hasExtension(r.URL.Path) { + fs.ServeHTTP(w, r) + } else { + file, err := staticFS.Open("index.html") + if err != nil { + http.Error(w, "index.html not found", http.StatusNotFound) + log.Logger.Error("Failed to open index.html:", err) + return + } + defer file.Close() + + data, err := io.ReadAll(file) + if err != nil { + http.Error(w, "Failed to read index.html", http.StatusInternalServerError) + log.Logger.Error("Failed to read index.html:", err) + return + } + + w.Header().Set("Content-Type", "text/html") + w.Write(data) } + })) +} - w.Header().Set("Content-Type", "text/html") - w.Write(data) - }) +func hasExtension(pathFile string) bool { + ext := strings.ToLower(path.Ext(pathFile)) + return ext != "" } diff --git a/frontend/src/components/notifications.tsx b/frontend/src/components/notifications.tsx index 78d813b..9935c94 100644 --- a/frontend/src/components/notifications.tsx +++ b/frontend/src/components/notifications.tsx @@ -26,16 +26,16 @@ const Notification: FC = ({ notification }) => { }, [dispatch, notification]); return ( -
+

{notification.message}

@@ -49,18 +49,18 @@ export const Notifications: FC = () => { const notifications = useAppSelector((state) => state.common.notifications); return ( -
+
{notifications.map((notification) => (