Add scss debug request endpoint

To help with debugging my scss.
This commit is contained in:
Eli Ribble 2026-02-03 23:12:40 +00:00
parent 26223ccc0a
commit fa0ac035ac
No known key found for this signature in database
2 changed files with 40 additions and 0 deletions

View file

@ -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)

39
rmo/scss.go Normal file
View file

@ -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")
}
}