make .html suffix optional
Signed-off-by: Tobias Erbshäußer <tobias@tesoft.dev>
This commit is contained in:
+14
-1
@@ -6,6 +6,19 @@ import (
|
|||||||
"os"
|
"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() {
|
func main() {
|
||||||
port := os.Getenv("PORT")
|
port := os.Getenv("PORT")
|
||||||
if port == "" {
|
if port == "" {
|
||||||
@@ -31,7 +44,7 @@ func main() {
|
|||||||
apiHandler := &ApiHandler{db: db}
|
apiHandler := &ApiHandler{db: db}
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
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) {
|
mux.Handle("GET /api/blog", apiHandler.ProcessAuth(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
apiHandler.ServeBlogGet(writer, request)
|
apiHandler.ServeBlogGet(writer, request)
|
||||||
}), false))
|
}), false))
|
||||||
|
|||||||
Reference in New Issue
Block a user