diff --git a/config/config.go b/config/config.go index a7e237d..6eeed93 100644 --- a/config/config.go +++ b/config/config.go @@ -30,12 +30,12 @@ func init() { ServerAddress = os.Getenv("SERVER_ADDRESS") - Prefix = os.Getenv("PREFIX") + Prefix = path.Join(os.Getenv("PREFIX")) DatabaseFile = os.Getenv("DATABASE_FILE") FrontendDir = os.Getenv("FRONTEND_DIR") PageBase = pageBase{ - BasePath: "http://" + path.Join(ServerAddress, Prefix), + BasePath: "http://" + path.Join(ServerAddress, Prefix) + "/", } } diff --git a/main.go b/main.go index f764fdd..0e7fae1 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/server/path.go b/server/path.go index f0aaa04..cb2eb27 100644 --- a/server/path.go +++ b/server/path.go @@ -5,10 +5,11 @@ import ( "net/http" "os" "path/filepath" + "strings" ) func ServePath(w http.ResponseWriter, r *http.Request) { - path := filepath.Join(config.FrontendDir, r.URL.Path) + path := filepath.Join(config.FrontendDir, strings.TrimPrefix(r.URL.Path, config.Prefix)) if _, err := os.Stat(path); os.IsNotExist(err) { Error404(w, r) } else {