Skip to content

Commit

Permalink
Improved startup messages to include the URL where the server is host…
Browse files Browse the repository at this point in the history
…ing (#10)

* Displayed URL in message
* Display "TLS disabled" when key or cert isn't present
  • Loading branch information
KenyC authored Oct 31, 2024
1 parent a3bd5af commit a664d41
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,23 @@ func (c *command) Run(ctx context.Context) error {
go func() {
serveTLS := *c.tlsCertPath != "" && *c.tlsKeyPath != ""

ancli.PrintfOK("now serving directory: '%v' on port: '%v', mirror dir is: '%v', tls: %v, certPath: '%v', keyPath: '%v'",
c.masterPath, *c.port, c.mirrorPath, serveTLS, *c.tlsCertPath, *c.tlsKeyPath)
hostname := "localhost" // default hostname
protocol := "http"
if serveTLS {
protocol = "https"
}
baseURL := fmt.Sprintf("%s://%s:%d", protocol, hostname, *c.port)

ancli.PrintfOK("Server started successfully:")
ancli.PrintfOK("- URL: %s", baseURL)
ancli.PrintfOK("- Serving directory: '%v'", c.masterPath)
ancli.PrintfOK("- Mirror directory: '%v'", c.mirrorPath)
if serveTLS {
ancli.PrintfOK("- TLS enabled (cert: '%v', key: '%v')", *c.tlsCertPath, *c.tlsKeyPath)
} else {
ancli.PrintfOK("- TLS disabled")
}

var err error
if serveTLS {
err = s.ListenAndServeTLS(*c.tlsCertPath, *c.tlsKeyPath)
Expand Down

0 comments on commit a664d41

Please sign in to comment.