diff --git a/auth/web.go b/auth/web.go index 9806312..57eed2f 100644 --- a/auth/web.go +++ b/auth/web.go @@ -3,19 +3,18 @@ package auth import ( "errors" "fmt" - "github.com/bouncepaw/mycorrhiza/viewutil" "io" "log" "mime" "net/http" "strings" + "github.com/bouncepaw/mycorrhiza/viewutil" + "github.com/gorilla/mux" "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" ) @@ -35,13 +34,6 @@ 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 6564943..d2a41fa 100644 --- a/misc/handlers.go +++ b/misc/handlers.go @@ -2,6 +2,15 @@ package misc import ( + "io" + "log" + "math/rand" + "mime" + "net/http" + "path/filepath" + + "github.com/gorilla/mux" + "github.com/bouncepaw/mycorrhiza/backlinks" "github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/files" @@ -12,15 +21,18 @@ import ( "github.com/bouncepaw/mycorrhiza/user" "github.com/bouncepaw/mycorrhiza/util" "github.com/bouncepaw/mycorrhiza/viewutil" - "github.com/gorilla/mux" - "io" - "log" - "math/rand" - "mime" - "net/http" - "path/filepath" ) +func InitAssetHandlers(rtr *mux.Router) { + rtr.HandleFunc("/static/style.css", handlerStyle) + rtr.HandleFunc("/robots.txt", handlerRobotsTxt) + rtr.PathPrefix("/static/"). + Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.FS)))) + rtr.HandleFunc("/favicon.ico", func(w http.ResponseWriter, rq *http.Request) { + http.Redirect(w, rq, "/static/favicon.ico", http.StatusSeeOther) + }) +} + func InitHandlers(rtr *mux.Router) { rtr.HandleFunc("/list", handlerList) rtr.HandleFunc("/reindex", handlerReindex) @@ -127,7 +139,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) @@ -142,7 +154,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") diff --git a/web/web.go b/web/web.go index 60e0cc1..299f9e5 100644 --- a/web/web.go +++ b/web/web.go @@ -2,6 +2,10 @@ package web import ( + "io" + "net/http" + "net/url" + "github.com/bouncepaw/mycorrhiza/admin" "github.com/bouncepaw/mycorrhiza/auth" "github.com/bouncepaw/mycorrhiza/backlinks" @@ -11,9 +15,6 @@ import ( "github.com/bouncepaw/mycorrhiza/hypview" "github.com/bouncepaw/mycorrhiza/interwiki" "github.com/bouncepaw/mycorrhiza/misc" - "io" - "net/http" - "net/url" "github.com/gorilla/mux" @@ -37,6 +38,7 @@ func Handler() http.Handler { router.StrictSlash(true) // Public routes. They're always accessible regardless of the user status. + misc.InitAssetHandlers(router) auth.InitAuth(router) // Wiki routes. They may be locked or restricted.