Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
server:
keepaliveperiodseconds: 0 # 0 = use Go default (15s); -1 = disable keepalive; set the interval in which keepalive packets will be sent. Only change this value if you know what you are doing.
listenaddr: "" # the address to bind on, leave empty to bind on all addresses. Prefix with "unix:" to create a unix socket. Example: "unix:/tmp/gotify.sock".
port: 80 # the port the HTTP server will listen on
port: 80 # the port the HTTP server will listen on, use -1 to disable the HTTP server

ssl:
enabled: false # if https should be enabled
Expand Down
31 changes: 21 additions & 10 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ func Run(router http.Handler, conf *config.Configuration) error {
shutdown := make(chan error)
go doShutdownOnSignal(shutdown)

httpListener, err := startListening("plain connection", conf.Server.ListenAddr, conf.Server.Port, conf.Server.KeepAlivePeriodSeconds)
if err != nil {
return err
s := &http.Server{Handler: router}

hasListener := false

if conf.Server.Port >= 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this instead be a enabled setting similar to the one for TLS? Should be default true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, but it would be called GOTIFY_SERVER_ENABLED=false which semantically sounds funny.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GOTIFY_SERVER_ENABLED=false it really looks confusing... Some may even think that "huh? My server disabled? :p"
But we can use like
GOTIFY_PLAIN_SERVER_ENABLED=false
Or
GOTIFY_HTTP_SERVER_ENABLED=false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I am trying to say is the name of these keys are tied to the yaml hierarchy by the configor, so if we add a key side by side with the current "port" key it would be called GOTIFY_SERVER_SOMETHING, which I don't like.

But I guess we can use GOTIFY_SERVER_DISABLE_HTTP or GOTIFY_SERVER_HTTP_FUNC=on/off/redirect , both should be good options forward

httpListener, err := startListening("plain connection", conf.Server.ListenAddr, conf.Server.Port, conf.Server.KeepAlivePeriodSeconds)
if err != nil {
return err
}
hasListener = true
defer httpListener.Close()
go func() {
err := s.Serve(httpListener)
doShutdown(shutdown, err)
}()
}
defer httpListener.Close()

s := &http.Server{Handler: router}
if conf.Server.SSL.Enabled {
if conf.Server.SSL.LetsEncrypt.Enabled {
applyLetsEncrypt(s, conf)
Expand All @@ -40,19 +50,20 @@ func Run(router http.Handler, conf *config.Configuration) error {
if err != nil {
return err
}
hasListener = true
defer httpsListener.Close()

go func() {
err := s.ServeTLS(httpsListener, conf.Server.SSL.CertFile, conf.Server.SSL.CertKey)
doShutdown(shutdown, err)
}()
}
go func() {
err := s.Serve(httpListener)
doShutdown(shutdown, err)
}()

err = <-shutdown
if !hasListener {
log.Fatalln("No listener started, both plain and TLS listeners are disabled")
}

err := <-shutdown
fmt.Println("Shutting down:", err)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down
Loading