mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-08-03 19:09:43 -04:00
chore(settings): default root url to / (cannot be empty)
This commit is contained in:
@@ -262,7 +262,7 @@ func _main(ctx context.Context, settingsSource SettingsSource, args []string, lo
|
||||
|
||||
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, address, config.Server.RootURL, db, serverLogger, runner)
|
||||
serverHandler, serverCtx, serverDone := goshutdown.NewGoRoutineHandler("server")
|
||||
go server.Run(serverCtx, serverDone)
|
||||
notify("Launched with " + strconv.Itoa(len(records)) + " records to watch")
|
||||
|
||||
@@ -10,18 +10,18 @@ import (
|
||||
|
||||
type Server struct {
|
||||
Port *uint16
|
||||
RootURL *string
|
||||
RootURL string
|
||||
}
|
||||
|
||||
func (s *Server) setDefaults() {
|
||||
const defaultPort = 8000
|
||||
s.Port = gosettings.DefaultPointer(s.Port, defaultPort)
|
||||
s.RootURL = gosettings.DefaultPointer(s.RootURL, "")
|
||||
s.RootURL = gosettings.DefaultString(s.RootURL, "/")
|
||||
}
|
||||
|
||||
func (s Server) mergeWith(other Server) (merged Server) {
|
||||
merged.Port = gosettings.MergeWithPointer(s.Port, other.Port)
|
||||
merged.RootURL = gosettings.MergeWithPointer(s.RootURL, other.RootURL)
|
||||
merged.RootURL = gosettings.MergeWithString(s.RootURL, other.RootURL)
|
||||
return merged
|
||||
}
|
||||
|
||||
|
||||
2
internal/config/sources/env/server.go
vendored
2
internal/config/sources/env/server.go
vendored
@@ -3,7 +3,7 @@ package env
|
||||
import "github.com/qdm12/ddns-updater/internal/config/settings"
|
||||
|
||||
func (s *Source) readServer() (settings settings.Server, err error) {
|
||||
settings.RootURL = s.env.Get("ROOT_URL")
|
||||
settings.RootURL = s.env.String("ROOT_URL")
|
||||
settings.Port, err = s.env.Uint16Ptr("LISTENING_PORT") // TODO change to address
|
||||
return settings, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"embed"
|
||||
"net/http"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
@@ -40,6 +41,7 @@ func newHandler(ctx context.Context, rootURL string,
|
||||
router := chi.NewRouter()
|
||||
|
||||
router.Use(middleware.Logger)
|
||||
rootURL = strings.TrimSuffix(rootURL, "/")
|
||||
|
||||
router.Get(rootURL+"/", handlers.index)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user