fix(config): treat directory as absent for optional config in cloud deploy mode

This commit is contained in:
hkfires
2025-10-10 19:40:02 +08:00
parent ac01c74c02
commit 78738ca3f0
2 changed files with 11 additions and 4 deletions

View File

@@ -127,10 +127,13 @@ func main() {
// Log if we're running without a config file in cloud deploy mode // Log if we're running without a config file in cloud deploy mode
var configFileExists bool var configFileExists bool
if isCloudDeploy { 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. // 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)") log.Info("Cloud deploy mode: No configuration file detected; standing by for configuration (API server not started)")
configFileExists = false 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 { } else {
log.Info("Cloud deploy mode: Configuration file detected; starting service") log.Info("Cloud deploy mode: Configuration file detected; starting service")
configFileExists = true configFileExists = true

View File

@@ -5,8 +5,10 @@
package config package config
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"syscall"
"github.com/router-for-me/CLIProxyAPI/v6/sdk/config" "github.com/router-for-me/CLIProxyAPI/v6/sdk/config"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
@@ -196,9 +198,11 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {
// Read the entire configuration file into memory. // Read the entire configuration file into memory.
data, err := os.ReadFile(configFile) data, err := os.ReadFile(configFile)
if err != nil { if err != nil {
if optional && os.IsNotExist(err) { if optional {
// Missing and optional: return empty config. if os.IsNotExist(err) || errors.Is(err, syscall.EISDIR) {
return &Config{}, nil // Missing and optional: return empty config (cloud deploy standby).
return &Config{}, nil
}
} }
return nil, fmt.Errorf("failed to read config file: %w", err) return nil, fmt.Errorf("failed to read config file: %w", err)
} }