mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-23 08:26:51 +00:00
Allow unauthenticated users to request static assets (#163)
This commit is contained in:
parent
aaff38a61c
commit
18ec5b669e
@ -14,6 +14,8 @@ import (
|
|||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/misc"
|
||||||
|
"github.com/bouncepaw/mycorrhiza/static"
|
||||||
"github.com/bouncepaw/mycorrhiza/user"
|
"github.com/bouncepaw/mycorrhiza/user"
|
||||||
"github.com/bouncepaw/mycorrhiza/util"
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
@ -33,6 +35,13 @@ func InitAuth(r *mux.Router) {
|
|||||||
}
|
}
|
||||||
r.HandleFunc("/login", handlerLogin)
|
r.HandleFunc("/login", handlerLogin)
|
||||||
r.HandleFunc("/logout", handlerLogout)
|
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) {
|
func handlerUserList(w http.ResponseWriter, rq *http.Request) {
|
||||||
|
@ -22,18 +22,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func InitHandlers(rtr *mux.Router) {
|
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("/list", handlerList)
|
||||||
rtr.HandleFunc("/reindex", handlerReindex)
|
rtr.HandleFunc("/reindex", handlerReindex)
|
||||||
rtr.HandleFunc("/update-header-links", handlerUpdateHeaderLinks)
|
rtr.HandleFunc("/update-header-links", handlerUpdateHeaderLinks)
|
||||||
rtr.HandleFunc("/random", handlerRandom)
|
rtr.HandleFunc("/random", handlerRandom)
|
||||||
rtr.HandleFunc("/about", handlerAbout)
|
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)
|
rtr.HandleFunc("/title-search/", handlerTitleSearch)
|
||||||
initViews()
|
initViews()
|
||||||
}
|
}
|
||||||
@ -134,7 +127,7 @@ func handlerAbout(w http.ResponseWriter, rq *http.Request) {
|
|||||||
|
|
||||||
var stylesheets = []string{"default.css", "custom.css"}
|
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"))
|
w.Header().Set("Content-Type", mime.TypeByExtension(".css"))
|
||||||
for _, name := range stylesheets {
|
for _, name := range stylesheets {
|
||||||
file, err := static.FS.Open(name)
|
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")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
|
||||||
file, err := static.FS.Open("robots.txt")
|
file, err := static.FS.Open("robots.txt")
|
||||||
|
Loading…
Reference in New Issue
Block a user