From 78738ca3f0dbb775d546d5e779c0ac4b8b4eb789 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 10 Oct 2025 19:40:02 +0800 Subject: [PATCH] fix(config): treat directory as absent for optional config in cloud deploy mode --- cmd/server/main.go | 5 ++++- internal/config/config.go | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 8c329259..03c754f0 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -127,10 +127,13 @@ func main() { // Log if we're running without a config file in cloud deploy mode var configFileExists bool if isCloudDeploy { - if _, err = os.Stat(configFilePath); os.IsNotExist(err) { + if info, errStat := os.Stat(configFilePath); errStat != nil { // Don't mislead: API server will not start until configuration is provided. log.Info("Cloud deploy mode: No configuration file detected; standing by for configuration (API server not started)") configFileExists = false + } else if info.IsDir() { + log.Info("Cloud deploy mode: Config path is a directory; standing by for configuration (API server not started)") + configFileExists = false } else { log.Info("Cloud deploy mode: Configuration file detected; starting service") configFileExists = true diff --git a/internal/config/config.go b/internal/config/config.go index 85548a69..b6b02fdc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,8 +5,10 @@ package config import ( + "errors" "fmt" "os" + "syscall" "github.com/router-for-me/CLIProxyAPI/v6/sdk/config" "golang.org/x/crypto/bcrypt" @@ -196,9 +198,11 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) { // Read the entire configuration file into memory. data, err := os.ReadFile(configFile) if err != nil { - if optional && os.IsNotExist(err) { - // Missing and optional: return empty config. - return &Config{}, nil + if optional { + if os.IsNotExist(err) || errors.Is(err, syscall.EISDIR) { + // Missing and optional: return empty config (cloud deploy standby). + return &Config{}, nil + } } return nil, fmt.Errorf("failed to read config file: %w", err) }