Finished subpath implementation

This commit is contained in:
2022-01-31 10:20:19 +01:00
parent 6ac80f8647
commit bc4c27cff3
3 changed files with 5 additions and 8 deletions

View File

@@ -11,7 +11,6 @@ import (
"net/http"
"path"
"path/filepath"
"strings"
)
func main() {
@@ -56,16 +55,13 @@ func setupApi(r *mux.Router) {
func setupFrontend(r *mux.Router) {
r.HandleFunc("/article/{article}", server.Article).Methods(http.MethodGet)
r.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filepath.Join(config.FrontendDir, "img", "logodark.svg"))
})
r.PathPrefix("/sass/").HandlerFunc(server.ServePath)
r.PathPrefix("/img/").HandlerFunc(server.ServePath)
landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml")))
r.PathPrefix("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.TrimPrefix(r.URL.Path, path.Dir(config.Prefix)) == "/" {
if path.Join(config.Prefix)+"/" == r.URL.Path {
landingpage.Execute(w, config.PageBase)
} else {
server.Error404(w, r)