fix: serve index.html for docs directory, update README with testing instructions
This commit is contained in:
@@ -2,6 +2,8 @@ package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/fiskerinc/cloud-services/pkg/utils/envtool"
|
||||
)
|
||||
@@ -12,6 +14,23 @@ func DocsHandler() http.Handler {
|
||||
if fp == "" {
|
||||
return nil
|
||||
}
|
||||
fs := http.FileServer(http.Dir(fp))
|
||||
return fs
|
||||
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Get the requested path
|
||||
reqPath := r.URL.Path
|
||||
if reqPath == "" || reqPath == "/" {
|
||||
reqPath = "/index.html"
|
||||
}
|
||||
|
||||
// Build full file path
|
||||
fullPath := path.Join(fp, reqPath)
|
||||
|
||||
// Check if it's a directory, serve index.html
|
||||
info, err := os.Stat(fullPath)
|
||||
if err == nil && info.IsDir() {
|
||||
fullPath = path.Join(fullPath, "index.html")
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, fullPath)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user