From fa0ac035ac33b16408a4c7ea624df53050221f6e Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 3 Feb 2026 23:12:40 +0000 Subject: [PATCH] Add scss debug request endpoint To help with debugging my scss. --- rmo/routes.go | 1 + rmo/scss.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 rmo/scss.go diff --git a/rmo/routes.go b/rmo/routes.go index 7cc8141b..ddb231ea 100644 --- a/rmo/routes.go +++ b/rmo/routes.go @@ -39,6 +39,7 @@ func Router() chi.Router { r.Post("/register-notifications", postRegisterNotifications) r.Get("/register-notifications-complete", getRegisterNotificationsComplete) r.Get("/search", getSearch) + r.Get("/scss/*", getScssDebug) r.Get("/status", getStatus) r.Get("/status/{report_id}", getStatusByID) r.Get("/terms-of-service", getTerms) diff --git a/rmo/scss.go b/rmo/scss.go new file mode 100644 index 00000000..e58c89c5 --- /dev/null +++ b/rmo/scss.go @@ -0,0 +1,39 @@ +package rmo + +import ( + "fmt" + "io" + "net/http" + "os" + + "github.com/go-chi/chi/v5" + "github.com/rs/zerolog/log" +) + +func getScssDebug(w http.ResponseWriter, r *http.Request) { + path := chi.URLParam(r, "*") + full_path := "scss/" + path + //log.Debug().Str("path", path).Str("full_path", full_path).Msg("working on SCSS debug") + file, err := os.Open(full_path) + if err != nil { + respondError(w, "failed to open file", err, http.StatusInternalServerError) + return + } + defer file.Close() + fileInfo, err := file.Stat() + if err != nil { + respondError(w, "failed to stat file", err, http.StatusInternalServerError) + return + } + // Set appropriate headers + w.Header().Set("Content-Type", "text/scss") + w.Header().Set("Content-Length", fmt.Sprintf("%d", fileInfo.Size())) + // Copy file contents to response writer + _, err = io.Copy(w, file) + if err != nil { + // Note: At this point, we've already started writing the response, + // so we can't change the status code anymore. The best we can do + // is log the error and abandon the connection. + log.Warn().Str("path", path).Msg("Failed to write scss file to output") + } +}