Allow root post

This commit is contained in:
Jan-Lukas Else 2020-07-29 17:26:33 +02:00
parent 9ee3c0c730
commit 8dbf795902
2 changed files with 6 additions and 8 deletions

View File

@ -56,15 +56,13 @@ func buildHandler() (http.Handler, error) {
r.Use(middleware.Recoverer)
r.Use(middleware.StripSlashes)
r.Get("/", hello)
allPostPaths, err := allPostPaths()
if err != nil {
return nil, err
} else {
for _, path := range allPostPaths {
if path != "" {
r.Get("/"+path, servePost)
r.Get(path, servePost)
}
}
}
@ -72,10 +70,6 @@ func buildHandler() (http.Handler, error) {
return r, nil
}
func hello(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte("Hello World!"))
}
type dynamicHandler struct {
realHandler http.Handler
changeMutex *sync.Mutex

View File

@ -18,7 +18,11 @@ type post struct {
}
func servePost(w http.ResponseWriter, r *http.Request) {
post, err := getPost(strings.TrimSuffix(strings.TrimPrefix(r.RequestURI, "/"), "/"), r.Context())
path := r.RequestURI
if len(path) > 1 {
path = strings.TrimSuffix(path, "/")
}
post, err := getPost(path, r.Context())
if err == postNotFound {
http.NotFound(w, r)
return