Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 8 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ 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
content string
}{
{"/index.html", "<html><body>Index</body></html>"},
{"/404.html", "<html><body>404 Not Found</body></html>"},
{"/docs.html", "<html><body>Index</body></html>"},
}

for _, file := range files {
Expand All @@ -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},
Expand Down