Backend changes for frontend changes

This commit is contained in:
2022-02-04 21:50:19 +01:00
parent a18a44b5fb
commit d4ac4409ad

View File

@@ -11,6 +11,7 @@ import (
"net/http" "net/http"
"path" "path"
"path/filepath" "path/filepath"
"strings"
) )
func main() { func main() {
@@ -62,15 +63,16 @@ func setupApi(r *mux.Router) {
func setupFrontend(r *mux.Router) { func setupFrontend(r *mux.Router) {
r.HandleFunc("/article/{article}", server.Article).Methods(http.MethodGet) r.HandleFunc("/article/{article}", server.Article).Methods(http.MethodGet)
r.PathPrefix("/sass/").HandlerFunc(server.ServePath) r.PathPrefix("/css/").HandlerFunc(server.ServePath)
r.PathPrefix("/img/").HandlerFunc(server.ServePath) r.PathPrefix("/img/").HandlerFunc(server.ServePath)
r.PathPrefix("/js/").HandlerFunc(server.ServePath) r.PathPrefix("/js/").HandlerFunc(server.ServePath)
r.PathPrefix("/html/").HandlerFunc(server.ServePath)
landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml"))) landingpage := template.Must(template.ParseFiles(filepath.Join(config.FrontendDir, "html", "landingpage.gohtml")))
r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { r.Path("/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
landingpage.Execute(w, struct { landingpage.Execute(w, struct {
BasePath string BasePath string
}{BasePath: config.Address + path.Join("/", config.SubPath) + "/"}) }{BasePath: config.Address + strings.TrimSuffix(path.Join("/", config.SubPath), "/") + "/"})
}) })
r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { r.NotFoundHandler = http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {