Skip to content

Commit

Permalink
pass caller URL in mail body
Browse files Browse the repository at this point in the history
  • Loading branch information
quantonganh committed Jan 3, 2024
1 parent 3b734d6 commit 8094df4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions http/newsletter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
func (s *Server) subscribeHandler(w http.ResponseWriter, r *http.Request) error {
email := r.FormValue("email")
subsReq := map[string]string{
"url": s.URL(),
"email": email,
}
req, err := json.Marshal(subsReq)
Expand Down
8 changes: 6 additions & 2 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (s *Server) Scheme() string {

// UseTLS checks if server use TLS or not
func (s *Server) UseTLS() bool {
return s.Domain != ""
return s.Domain != "localhost"
}

// Port returns server port
Expand All @@ -147,7 +147,11 @@ func (s *Server) URL() string {
domain = s.Domain
}

if port == 80 || port == 443 || flag.Lookup("test.v") != nil {
if flag.Lookup("test.v") != nil {
return fmt.Sprintf("http://%s", domain)
}

if port == 80 || port == 443 {
return fmt.Sprintf("%s://%s", scheme, domain)
}
return fmt.Sprintf("%s://%s:%d", scheme, domain, s.Port())
Expand Down

0 comments on commit 8094df4

Please sign in to comment.