mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40:26 +00:00
Fix static assets not served on wikis with no auth
This commit is contained in:
parent
945cdc934c
commit
4831e4c7af
12
auth/web.go
12
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) {
|
||||
|
@ -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")
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user