diff --git a/main.go b/main.go index 9aadb86..f510abe 100644 --- a/main.go +++ b/main.go @@ -36,10 +36,10 @@ func main() { if r.URL.Path == rootPath { filePath += indexHTML } else if !ok { - if stat, err := os.Stat(filePath); err == nil && stat.IsDir() { - filePath += indexHTML - } else { + if _, err := os.Stat(filePath + ".html"); err == nil { filePath += htmlExtension + } else if stat, err := os.Stat(filePath); err == nil && stat.IsDir() { + filePath += indexHTML } } diff --git a/main_test.go b/main_test.go index 7d67c11..d105f04 100644 --- a/main_test.go +++ b/main_test.go @@ -14,6 +14,12 @@ func TestServer(t *testing.T) { //nolint:staticcheck // Ignore as we are testing the server tempDir := os.TempDir() + // Create an "index" directory + indexDirPath := filepath.Join(tempDir, "docs") + if err := os.MkdirAll(indexDirPath, 0600); err != nil { + t.Fatalf("Failed to create directory %s: %v", indexDirPath, err) + } + // Create necessary files files := []struct { name string @@ -21,6 +27,7 @@ func TestServer(t *testing.T) { }{ {"/index.html", "Index"}, {"/404.html", "404 Not Found"}, + {"/docs.html", "Index"}, } for _, file := range files { @@ -46,6 +53,7 @@ func TestServer(t *testing.T) { statusCode int }{ {"/", http.StatusOK}, + {"/docs", http.StatusOK}, {"/index", http.StatusOK}, {"/index/", http.StatusOK}, {tempDir + "/index.html", http.StatusNotFound},