httpd: disable directory index for static files

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-09-08 19:55:45 +02:00
parent dc7c829b73
commit fac022090d
6 changed files with 31 additions and 12 deletions

View File

@@ -18,16 +18,20 @@
package httpd
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/drakkan/sftpgo/v2/internal/bundle"
)
func serveStaticDir(router chi.Router, path, _ string) {
func serveStaticDir(router chi.Router, path, fsDirPath string, disableDirectoryIndex bool) {
switch path {
case webStaticFilesPath:
fileServer(router, path, bundle.GetStaticFs())
fileServer(router, path, bundle.GetStaticFs(), disableDirectoryIndex)
case webOpenAPIPath:
fileServer(router, path, bundle.GetOpenAPIFs())
fileServer(router, path, bundle.GetOpenAPIFs(), disableDirectoryIndex)
default:
fileServer(router, path, http.Dir(fsDirPath), disableDirectoryIndex)
}
}