Skip to content

Commit

Permalink
Fixing the issues with the reverse proxy (#242)
Browse files Browse the repository at this point in the history
- Fixed an issue where the reverse proxy would fail to initialize due to prot conflict and any attempt to restart would crash
- fixed an issue where we allowed routes to be created even if the reverse proxy was disabled
- fixed an issue where if the config changes in memory we would not save those changes
- added the ability to choose the port and host trough configuration or env variables
  • Loading branch information
cjlapao authored Nov 18, 2024
1 parent 5b5e419 commit 1a9730b
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 178 deletions.
38 changes: 17 additions & 21 deletions src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,29 +506,25 @@ func (c *Config) IsReverseProxyEnabled() bool {
return true
}

func (c *Config) GetReverseProxyConfig() *ReverseProxyConfig {
if c.config.ReverseProxy == nil {
c.config.ReverseProxy = &ReverseProxyConfig{
Host: "localhost",
Port: "8080",
}
if c.TlsEnabled() {
c.config.ReverseProxy.Ssl = &ReverseProxyConfigSsl{
Enabled: true,
Cert: c.TlsCertificate(),
Key: c.TlsPrivateKey(),
}
}
if c.IsCorsEnabled() {
c.config.ReverseProxy.Cors = &ReverseProxyConfigCors{
Enabled: true,
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH", "CONNECT", "TRACE"},
AllowedHeaders: []string{"*"},
}
}
func (c *Config) ReverseProxyHost() string {
host := c.GetKey(constants.REVERSE_PROXY_HOST_ENV_VAR)
if host == "" {
host = constants.DEFAULT_REVERSE_PROXY_HOST
}

return host
}

func (c *Config) ReverseProxyPort() string {
port := c.GetKey(constants.REVERSE_PROXY_PORT_ENV_VAR)
if port == "" {
port = constants.DEFAULT_REVERSE_PROXY_PORT
}

return port
}

func (c *Config) GetReverseProxyConfig() *ReverseProxyConfig {
return c.config.ReverseProxy
}

Expand Down
2 changes: 2 additions & 0 deletions src/constants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
DEFAULT_SYSTEM_RESERVED_CPU = 1
DEFAULT_SYSTEM_RESERVED_MEMORY = 2048
DEFAULT_SYSTEM_RESERVED_DISK = 20000
DEFAULT_REVERSE_PROXY_PORT = "5080"
DEFAULT_REVERSE_PROXY_HOST = "0.0.0.0"

API_MODE = "api"
CLI_MODE = "cli"
Expand Down
Loading

0 comments on commit 1a9730b

Please sign in to comment.