Implement hybrid CSS architecture to fix white-on-white modal issue on sites with CSS resets
- Migrate from inline CSS to external insertr.css with cascade layer architecture
- Add CSS CDN serving capability (ServeInsertrCSS handler and /insertr.css route)
- Implement hybrid approach: @layer insertr for modern browsers + html body selectors for legacy browsers
- Remove scattered inline CSS from JavaScript modules for better maintainability
- Solve form element spacing conflicts with aggressive site CSS resets like '* {margin:0; padding:0}'
- Enable proper CSS caching and separation of concerns
This commit is contained in:
16
cmd/serve.go
16
cmd/serve.go
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -143,6 +144,7 @@ func runServe(cmd *cobra.Command, args []string) {
|
||||
|
||||
// Static library serving (for demo sites)
|
||||
router.Get("/insertr.js", contentHandler.ServeInsertrJS)
|
||||
router.Get("/insertr.css", contentHandler.ServeInsertrCSS)
|
||||
|
||||
// API routes
|
||||
router.Route("/api", func(apiRouter chi.Router) {
|
||||
@@ -163,11 +165,21 @@ func runServe(cmd *cobra.Command, args []string) {
|
||||
})
|
||||
|
||||
// Static site serving - serve registered sites at /sites/{site_id}
|
||||
// This fixes the MIME type issues with Chi's FileServer
|
||||
// Custom file server that fixes CSS MIME types
|
||||
for siteID, siteConfig := range siteManager.GetAllSites() {
|
||||
log.Printf("📁 Serving site %s from %s at /sites/%s/", siteID, siteConfig.Path, siteID)
|
||||
|
||||
// Create custom file server with MIME type fixing
|
||||
fileServer := http.FileServer(http.Dir(siteConfig.Path))
|
||||
router.Handle("/sites/"+siteID+"/*", http.StripPrefix("/sites/"+siteID+"/", fileServer))
|
||||
customHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Fix MIME type for CSS files (including extensionless ones in css/ directory)
|
||||
if strings.Contains(r.URL.Path, "/css/") {
|
||||
w.Header().Set("Content-Type", "text/css; charset=utf-8")
|
||||
}
|
||||
fileServer.ServeHTTP(w, r)
|
||||
})
|
||||
|
||||
router.Handle("/sites/"+siteID+"/*", http.StripPrefix("/sites/"+siteID+"/", customHandler))
|
||||
}
|
||||
|
||||
// Start server
|
||||
|
||||
Reference in New Issue
Block a user