fix: serve index.html for docs directory, update README with testing instructions

This commit is contained in:
Chris Rai
2026-01-31 14:34:45 -05:00
parent 5e2c13c57e
commit a0ec642ca1
2 changed files with 61 additions and 23 deletions

View File

@@ -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)
})
}