Skip to content

Commit

Permalink
Issue #40:http protocol is hardcoded in the URL
Browse files Browse the repository at this point in the history
   - moved hardcoded protocol to an argument
  • Loading branch information
oneils committed Sep 15, 2024
1 parent 26c897f commit 2db4c8c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ _Feel free to suggest any other ways to make the process safer._
- MAX_EXPIRE - maximum lifetime period, default 24h
- PIN_SIZE - size (in characters) of the pin, default 5
- PIN_ATTEMPTS - maximum number of failed attempts to enter pin, default 3
- PROTOCOL - http or https
1. Setup SSL:
- The system can make valid certificates for you automatically with integrated [nginx-le](https://github.com/umputun/nginx-le). Just set:
- LETSENCRYPT=true
Expand Down
2 changes: 2 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var opts struct {
WebRoot string `long:"web" env:"WEB" default:"./ui/static/" description:"web ui location"`
Dbg bool `long:"dbg" description:"debug mode"`
Domain string `short:"d" long:"domain" env:"DOMAIN" description:"site domain" required:"true"`
Protocol string `short:"p" long:"protocol" env:"PROTOCOL" description:"site protocol" choice:"http" choice:"https" default:"https" required:"true"` // nolint
}

var revision string
Expand All @@ -42,6 +43,7 @@ func main() {

srv, err := server.New(messager.New(dataStore, crypter, params), revision, server.Config{
Domain: opts.Domain,
Protocol: opts.Protocol,
PinSize: opts.PinSize,
MaxPinAttempts: opts.MaxPinAttempts,
MaxExpire: opts.MaxExpire,
Expand Down
1 change: 1 addition & 0 deletions app/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
type Config struct {
Domain string
WebRoot string
Protocol string
// Validation parameters
PinSize int
MaxPinAttempts int
Expand Down
2 changes: 1 addition & 1 deletion app/server/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (s Server) generateLinkCtrl(w http.ResponseWriter, r *http.Request) {
return
}

msgURL := fmt.Sprintf("http://%s/message/%s", s.cfg.Domain, msg.Key)
msgURL := fmt.Sprintf("%s://%s/message/%s", s.cfg.Protocol, s.cfg.Domain, msg.Key)

s.render(w, http.StatusOK, "secure-link.tmpl.html", "secure-link", msgURL)
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ services:
- PIN_ATTEMPTS=3
- MAX_EXPIRE=24h
- DOMAIN=localhost:8080
- PROTOCOL=http
ports:
- "8080:8080"

0 comments on commit 2db4c8c

Please sign in to comment.