make .html suffix optional

Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
2026-05-24 09:23:05 +02:00
parent 31cc11a2f6
commit 04b5b0b75d
+14 -1
View File
@@ -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))