diff --git a/auth/web.go b/auth/web.go index 690fa2d..9806312 100644 --- a/auth/web.go +++ b/auth/web.go @@ -14,6 +14,8 @@ import ( "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/l18n" + "github.com/bouncepaw/mycorrhiza/misc" + "github.com/bouncepaw/mycorrhiza/static" "github.com/bouncepaw/mycorrhiza/user" "github.com/bouncepaw/mycorrhiza/util" ) @@ -33,6 +35,13 @@ func InitAuth(r *mux.Router) { } r.HandleFunc("/login", handlerLogin) r.HandleFunc("/logout", handlerLogout) + r.HandleFunc("/static/style.css", misc.HandlerStyle) + r.HandleFunc("/robots.txt", misc.HandlerRobotsTxt) + r.PathPrefix("/static/"). + Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.FS)))) + r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) { + http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther) + }) } func handlerUserList(w http.ResponseWriter, rq *http.Request) { diff --git a/misc/handlers.go b/misc/handlers.go index fee9b6e..6564943 100644 --- a/misc/handlers.go +++ b/misc/handlers.go @@ -22,18 +22,11 @@ import ( ) func InitHandlers(rtr *mux.Router) { - rtr.HandleFunc("/robots.txt", handlerRobotsTxt) - rtr.HandleFunc("/static/style.css", handlerStyle) - rtr.PathPrefix("/static/"). - Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.FS)))) rtr.HandleFunc("/list", handlerList) rtr.HandleFunc("/reindex", handlerReindex) rtr.HandleFunc("/update-header-links", handlerUpdateHeaderLinks) rtr.HandleFunc("/random", handlerRandom) rtr.HandleFunc("/about", handlerAbout) - rtr.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) { - http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther) - }) rtr.HandleFunc("/title-search/", handlerTitleSearch) initViews() } @@ -134,7 +127,7 @@ func handlerAbout(w http.ResponseWriter, rq *http.Request) { var stylesheets = []string{"default.css", "custom.css"} -func handlerStyle(w http.ResponseWriter, rq *http.Request) { +func HandlerStyle(w http.ResponseWriter, rq *http.Request) { w.Header().Set("Content-Type", mime.TypeByExtension(".css")) for _, name := range stylesheets { file, err := static.FS.Open(name) @@ -149,7 +142,7 @@ func handlerStyle(w http.ResponseWriter, rq *http.Request) { } } -func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) { +func HandlerRobotsTxt(w http.ResponseWriter, rq *http.Request) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") file, err := static.FS.Open("robots.txt")