diff --git a/config.go b/config.go index 686ea6c..a3893ae 100644 --- a/config.go +++ b/config.go @@ -2,6 +2,7 @@ package main import ( "errors" + "path/filepath" "github.com/BurntSushi/toml" ) @@ -79,5 +80,16 @@ func getConfig(filename string) (Config, error) { return config, errors.New("Invalid DirectorySort value.") } + // Expand CGI paths + var cgiPaths []string + for _, cgiPath := range config.CGIPaths { + expandedPaths, err := filepath.Glob(cgiPath) + if err != nil { + return config, errors.New("Error expanding CGI path glob " + cgiPath + ": " + err.Error()) + } + cgiPaths = append(cgiPaths, expandedPaths...) + } + config.CGIPaths = cgiPaths + return config, nil } diff --git a/handler.go b/handler.go index 2fad0ef..c85d5d5 100644 --- a/handler.go +++ b/handler.go @@ -100,16 +100,7 @@ func handleGeminiRequest(conn net.Conn, config Config, accessLogEntries chan Log } // Check whether this URL is in a configured CGI path - var cgiPaths []string for _, cgiPath := range config.CGIPaths { - expandedPaths, err := filepath.Glob(cgiPath) - if err != nil { - errorLogEntries <- "Error expanding CGI path glob " + cgiPath + ": " + err.Error() - continue - } - cgiPaths = append(cgiPaths, expandedPaths...) - } - for _, cgiPath := range cgiPaths { if strings.HasPrefix(path, cgiPath) { handleCGI(config, path, cgiPath, URL, &log, errorLogEntries, conn) if log.Status != 0 {