Skip to content

Commit 0aace26

Browse files
committed
feat: new file_server_mode (bool) key
1 parent 7a5b9cd commit 0aace26

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type SiteConfig struct {
3939
BufferSizeKB int `json:"buffer_size_kb"`
4040
MaxConcurrentConnections int `json:"max_concurrent_connections"`
4141
EnableLogging *bool `json:"enable_logging,omitempty"` // Default true if nil
42+
FileServerMode bool `json:"file_server_mode"` // Disables custom pages, enables directory listing
4243

4344
PluginConfigs map[string]interface{} `json:"plugin_configs"`
4445
}

internal/server/handler.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,21 @@ func createHandler(conf config.SiteConfig, log *logger.Logger, identifier string
3333
})
3434

3535
} else {
36-
// Serve static files from the root directory using the Smart Static Handler
37-
// for compression.
38-
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39-
addCustomHeaders(w, conf.CustomHeaders)
40-
ServeStatic(w, r, conf.RootDirectory)
41-
})
36+
// Serve static files from the root directory
37+
if conf.FileServerMode {
38+
// File Server Mode: use standard http.FileServer with directory listing
39+
fs := http.FileServer(http.Dir(conf.RootDirectory))
40+
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
41+
addCustomHeaders(w, conf.CustomHeaders)
42+
fs.ServeHTTP(w, r)
43+
})
44+
} else {
45+
// Smart Static Handler with custom error pages
46+
handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
47+
addCustomHeaders(w, conf.CustomHeaders)
48+
ServeStatic(w, r, conf.RootDirectory)
49+
})
50+
}
4251
}
4352

4453
// Copy the global middleware manager for this site

0 commit comments

Comments
 (0)