diff --git a/backend/main.go b/backend/main.go index 6f0e153..40ba3f1 100644 --- a/backend/main.go +++ b/backend/main.go @@ -6,6 +6,19 @@ import ( "os" ) +type HtmlDir struct { + dir http.Dir +} + +func (dir HtmlDir) Open(name string) (http.File, error) { + file, err := dir.dir.Open(name) + if os.IsNotExist(err) { + file, err = dir.dir.Open(name + ".html") + } + + return file, err +} + func main() { port := os.Getenv("PORT") if port == "" { @@ -31,7 +44,7 @@ func main() { apiHandler := &ApiHandler{db: db} mux := http.NewServeMux() - mux.Handle("/", http.FileServer(http.Dir(frontendPath))) + mux.Handle("/", http.FileServer(HtmlDir{http.Dir(frontendPath)})) mux.Handle("GET /api/blog", apiHandler.ProcessAuth(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { apiHandler.ServeBlogGet(writer, request) }), false))