vuonglv(Andy) commited on
Commit
e0bd512
·
unverified ·
1 Parent(s): 58406f8

feat(config): add configurable host binding for server (#454)

Browse files
config.example.yaml CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  # Server port
2
  port: 8317
3
 
 
1
+ # Server host/interface to bind to. Default is empty ("") to bind all interfaces (IPv4 + IPv6).
2
+ # Use "127.0.0.1" or "localhost" to restrict access to local machine only.
3
+ host: ""
4
+
5
  # Server port
6
  port: 8317
7
 
internal/api/server.go CHANGED
@@ -300,7 +300,7 @@ func NewServer(cfg *config.Config, authManager *auth.Manager, accessManager *sdk
300
 
301
  // Create HTTP server
302
  s.server = &http.Server{
303
- Addr: fmt.Sprintf(":%d", cfg.Port),
304
  Handler: engine,
305
  }
306
 
 
300
 
301
  // Create HTTP server
302
  s.server = &http.Server{
303
+ Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
304
  Handler: engine,
305
  }
306
 
internal/config/config.go CHANGED
@@ -20,6 +20,9 @@ import (
20
  // Config represents the application's configuration, loaded from a YAML file.
21
  type Config struct {
22
  config.SDKConfig `yaml:",inline"`
 
 
 
23
  // Port is the network port on which the API server will listen.
24
  Port int `yaml:"port" json:"-"`
25
 
@@ -320,6 +323,7 @@ func LoadConfigOptional(configFile string, optional bool) (*Config, error) {
320
  // Unmarshal the YAML data into the Config struct.
321
  var cfg Config
322
  // Set defaults before unmarshal so that absent keys keep defaults.
 
323
  cfg.LoggingToFile = false
324
  cfg.UsageStatisticsEnabled = false
325
  cfg.DisableCooling = false
 
20
  // Config represents the application's configuration, loaded from a YAML file.
21
  type Config struct {
22
  config.SDKConfig `yaml:",inline"`
23
+ // Host is the network host/interface on which the API server will bind.
24
+ // Default is empty ("") to bind all interfaces (IPv4 + IPv6). Use "127.0.0.1" or "localhost" for local-only access.
25
+ Host string `yaml:"host" json:"-"`
26
  // Port is the network port on which the API server will listen.
27
  Port int `yaml:"port" json:"-"`
28
 
 
323
  // Unmarshal the YAML data into the Config struct.
324
  var cfg Config
325
  // Set defaults before unmarshal so that absent keys keep defaults.
326
+ cfg.Host = "" // Default empty: binds to all interfaces (IPv4 + IPv6)
327
  cfg.LoggingToFile = false
328
  cfg.UsageStatisticsEnabled = false
329
  cfg.DisableCooling = false
sdk/cliproxy/service.go CHANGED
@@ -498,7 +498,7 @@ func (s *Service) Run(ctx context.Context) error {
498
  }()
499
 
500
  time.Sleep(100 * time.Millisecond)
501
- fmt.Printf("API server started successfully on: %d\n", s.cfg.Port)
502
 
503
  if s.hooks.OnAfterStart != nil {
504
  s.hooks.OnAfterStart(s)
 
498
  }()
499
 
500
  time.Sleep(100 * time.Millisecond)
501
+ fmt.Printf("API server started successfully on: %s:%d\n", s.cfg.Host, s.cfg.Port)
502
 
503
  if s.hooks.OnAfterStart != nil {
504
  s.hooks.OnAfterStart(s)