mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-04-05 08:54:09 -04:00
feat(config): LISTENING_ADDRESS configuration key (#590)
This commit is contained in:
@@ -86,7 +86,7 @@ ENV \
|
||||
RESOLVER_ADDRESS= \
|
||||
RESOLVER_TIMEOUT=5s \
|
||||
# Web UI
|
||||
LISTENING_PORT=8000 \
|
||||
LISTENING_PORT=:8000 \
|
||||
ROOT_URL=/ \
|
||||
# Backup
|
||||
BACKUP_PERIOD=0 \
|
||||
|
||||
@@ -234,7 +234,7 @@ Note that:
|
||||
| `PUBLICIP_DNS_TIMEOUT` | `3s` | Public IP DNS query timeout |
|
||||
| `UPDATE_COOLDOWN_PERIOD` | `5m` | Duration to cooldown between updates for each record. This is useful to avoid being rate limited or banned. |
|
||||
| `HTTP_TIMEOUT` | `10s` | Timeout for all HTTP requests |
|
||||
| `LISTENING_PORT` | `8000` | Internal TCP listening port for the web UI |
|
||||
| `LISTENING_PORT` | `:8000` | Internal TCP listening port for the web UI |
|
||||
| `ROOT_URL` | `/` | URL path to append to all paths to the webUI (i.e. `/ddns` for accessing `https://example.com/ddns` through a proxy) |
|
||||
| `HEALTH_SERVER_ADDRESS` | `127.0.0.1:9999` | Health server listening address |
|
||||
| `HEALTH_HEALTHCHECKSIO_UUID` | | UUID for [healthchecks.io](https://healthchecks.io) to send a heartbeat on every update check |
|
||||
|
||||
@@ -265,9 +265,9 @@ func _main(ctx context.Context, reader *reader.Reader, args []string, logger log
|
||||
healthServerHandler, healthServerCtx, healthServerDone := goshutdown.NewGoRoutineHandler("health server")
|
||||
go healthServer.Run(healthServerCtx, healthServerDone)
|
||||
|
||||
address := ":" + fmt.Sprint(*config.Server.Port)
|
||||
serverLogger := logger.New(log.SetComponent("http server"))
|
||||
server := server.New(ctx, address, config.Server.RootURL, db, serverLogger, runner)
|
||||
server := server.New(ctx, config.Server.ListeningAddress, config.Server.RootURL,
|
||||
db, serverLogger, runner)
|
||||
serverHandler, serverCtx, serverDone := goshutdown.NewGoRoutineHandler("server")
|
||||
go server.Run(serverCtx, serverDone)
|
||||
shoutrrrClient.Notify("Launched with " + strconv.Itoa(len(records)) + " records to watch")
|
||||
|
||||
@@ -21,7 +21,7 @@ services:
|
||||
- HTTP_TIMEOUT=10s
|
||||
|
||||
# Web UI
|
||||
- LISTENING_PORT=8000
|
||||
- LISTENING_ADDRESS=:8000
|
||||
- ROOT_URL=/
|
||||
|
||||
# Backup
|
||||
|
||||
@@ -11,19 +11,17 @@ import (
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Port *uint16
|
||||
RootURL string
|
||||
ListeningAddress string
|
||||
RootURL string
|
||||
}
|
||||
|
||||
func (s *Server) setDefaults() {
|
||||
const defaultPort = 8000
|
||||
s.Port = gosettings.DefaultPointer(s.Port, defaultPort)
|
||||
s.ListeningAddress = gosettings.DefaultComparable(s.ListeningAddress, ":8000")
|
||||
s.RootURL = gosettings.DefaultComparable(s.RootURL, "/")
|
||||
}
|
||||
|
||||
func (s Server) Validate() (err error) {
|
||||
listeningAddress := ":" + fmt.Sprint(*s.Port)
|
||||
err = validate.ListeningAddress(listeningAddress, os.Getuid())
|
||||
err = validate.ListeningAddress(s.ListeningAddress, os.Getuid())
|
||||
if err != nil {
|
||||
return fmt.Errorf("listening address: %w", err)
|
||||
}
|
||||
@@ -39,13 +37,24 @@ func (s Server) String() string {
|
||||
|
||||
func (s Server) toLinesNode() *gotree.Node {
|
||||
node := gotree.New("Server")
|
||||
node.Appendf("Port: %d", *s.Port)
|
||||
node.Appendf("Listening address: %s", s.ListeningAddress)
|
||||
node.Appendf("Root URL: %s", s.RootURL)
|
||||
return node
|
||||
}
|
||||
|
||||
func (s *Server) read(reader *reader.Reader) (err error) {
|
||||
func (s *Server) read(reader *reader.Reader, warner Warner) (err error) {
|
||||
s.RootURL = reader.String("ROOT_URL")
|
||||
s.Port, err = reader.Uint16Ptr("LISTENING_PORT") // TODO change to address
|
||||
|
||||
// Retro-compatibility
|
||||
port, err := reader.Uint16Ptr("LISTENING_PORT") // TODO change to address
|
||||
if err != nil {
|
||||
handleDeprecated(warner, "LISTENING_PORT", "LISTENING_ADDRESS")
|
||||
return err
|
||||
} else if port != nil {
|
||||
s.ListeningAddress = fmt.Sprintf(":%d", *port)
|
||||
}
|
||||
|
||||
s.ListeningAddress = reader.String("LISTENING_ADDRESS")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func (c *Config) Read(reader *reader.Reader,
|
||||
|
||||
c.IPv6.read(reader)
|
||||
|
||||
err = c.Server.read(reader)
|
||||
err = c.Server.read(reader, warner)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading server settings: %w", err)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func Test_Settings_String(t *testing.T) {
|
||||
├── IPv6
|
||||
| └── Prefix: /128
|
||||
├── Server
|
||||
| ├── Port: 8000
|
||||
| ├── Listening address: :8000
|
||||
| └── Root URL: /
|
||||
├── Health
|
||||
| └── Server listening address: 127.0.0.1:9999
|
||||
|
||||
Reference in New Issue
Block a user