1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-12-08 09:28:10 +00:00

Fix static assets not served on wikis with no auth

This commit is contained in:
Umar Getagazov
2022-08-21 16:25:47 +03:00
parent 945cdc934c
commit 4831e4c7af
3 changed files with 28 additions and 22 deletions

View File

@@ -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")