mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-12-20 23:28:07 +00:00
Misc: Move more stuff here
This commit is contained in:
46
web/web.go
46
web/web.go
@@ -4,54 +4,17 @@ package web
|
||||
import (
|
||||
"github.com/bouncepaw/mycorrhiza/categories"
|
||||
"github.com/bouncepaw/mycorrhiza/misc"
|
||||
"github.com/bouncepaw/mycorrhiza/viewutil"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/cfg"
|
||||
"github.com/bouncepaw/mycorrhiza/l18n"
|
||||
"github.com/bouncepaw/mycorrhiza/static"
|
||||
"github.com/bouncepaw/mycorrhiza/user"
|
||||
"github.com/bouncepaw/mycorrhiza/util"
|
||||
"github.com/bouncepaw/mycorrhiza/views"
|
||||
)
|
||||
|
||||
var stylesheets = []string{"default.css", "custom.css"}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
io.Copy(w, file)
|
||||
file.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func handlerUserList(w http.ResponseWriter, rq *http.Request) {
|
||||
lc := l18n.FromRequest(rq)
|
||||
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(views.Base(viewutil.MetaFrom(w, rq), lc.Get("ui.users_title"), views.UserList(lc))))
|
||||
}
|
||||
|
||||
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")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
io.Copy(w, file)
|
||||
file.Close()
|
||||
}
|
||||
|
||||
// Handler initializes and returns the HTTP router based on the configuration.
|
||||
func Handler() http.Handler {
|
||||
router := mux.NewRouter()
|
||||
@@ -68,10 +31,6 @@ func Handler() http.Handler {
|
||||
|
||||
// Public routes. They're always accessible regardless of the user status.
|
||||
initAuth(router)
|
||||
router.HandleFunc("/robots.txt", handlerRobotsTxt)
|
||||
router.HandleFunc("/static/style.css", handlerStyle)
|
||||
router.PathPrefix("/static/").
|
||||
Handler(http.StripPrefix("/static/", http.FileServer(http.FS(static.FS))))
|
||||
|
||||
// Wiki routes. They may be locked or restricted.
|
||||
wikiRouter := router.PathPrefix("").Subrouter()
|
||||
@@ -87,7 +46,7 @@ func Handler() http.Handler {
|
||||
initReaders(wikiRouter)
|
||||
initMutators(wikiRouter)
|
||||
initHistory(wikiRouter)
|
||||
initStuff(wikiRouter)
|
||||
initHelp(wikiRouter)
|
||||
initSearch(wikiRouter)
|
||||
initBacklinks(wikiRouter)
|
||||
categories.InitHandlers(wikiRouter)
|
||||
@@ -100,9 +59,6 @@ func Handler() http.Handler {
|
||||
initAdmin(adminRouter)
|
||||
}
|
||||
|
||||
// Miscellaneous
|
||||
wikiRouter.HandleFunc("/user-list", handlerUserList)
|
||||
|
||||
// Index page
|
||||
wikiRouter.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {
|
||||
// Let's pray it never fails
|
||||
|
||||
Reference in New Issue
Block a user