Port 443 for Caddy so we have nice links in emails. No need for weird ports.

This commit is contained in:
Daniel Krol 2022-08-13 15:03:06 -04:00
parent 0e36bebdae
commit d1c5685045
6 changed files with 14 additions and 25 deletions

View file

@ -4,14 +4,14 @@ Install the latest version of golang. Check out this repository, and run `go bui
Insteall the [caddy web server](https://caddyserver.com/). The website has its own debian repos. You can also install from source (golang). Which ever (if either) you feel comfortable with. No specific recommendations here.
You'll need to adjust your firewall to allow http (port 80) for caddy to obtain an SSL cert via ACME (ZeroSSL or LetsEncrypt) and also allow the port you set to have caddy serve on (we use 8091, but it probably also be 80). If you use `ufw`:
You'll need to adjust your firewall to allow http (port 80) for caddy to obtain an SSL cert via ACME (ZeroSSL or LetsEncrypt) and also allow https (port 443) to have caddy serve our wallet sync server. If you use `ufw`:
```
sudo ufw allow http
sudo ufw allow 8091
sudo ufw allow https
```
To avoid running Caddy as root, you'll need to allow it to serve from port 80 ([see here](https://superuser.com/a/892391)):
To avoid running Caddy as root, you'll need to allow it to serve from ports 80 and 443 ([see here](https://superuser.com/a/892391)):
```
sudo setcap 'cap_net_bind_service=+ep' /home/lbry/caddy/cmd/caddy/caddy

View file

@ -1,5 +1,5 @@
[program:caddy]
command={caddy-cmd} reverse-proxy --from dev.lbry.id:8091 --to localhost:8090
command={caddy-cmd} reverse-proxy --from dev.lbry.id:443 --to localhost:8090
user={lbry-user}
autostart=true
autorestart=true

View file

@ -23,8 +23,7 @@ type MailInterface interface {
}
type Mail struct {
ServerPort int
Env env.EnvInterface
Env env.EnvInterface
}
// Split out everything I can to make it testable. Right now
@ -58,7 +57,7 @@ func (m *Mail) prepareMessage(token auth.VerifyTokenString) (
sender = fmt.Sprintf("wallet-sync@%s", sendingDomain)
subject = fmt.Sprintf("Verify your wallet sync account on %s", serverDomain)
url := fmt.Sprintf("https://%s:%d%s?verifyToken=%s", serverDomain, m.ServerPort, paths.PathVerify, token)
url := fmt.Sprintf("https://%s%s?verifyToken=%s", serverDomain, paths.PathVerify, token)
text = fmt.Sprintf("Click here to verify your account:\n\n%s", url)
html = fmt.Sprintf("Click here to verify your account:\n\n<a href=\"%s\">%s</a>", url, url)

View file

@ -1,7 +1,6 @@
package mail
import (
"fmt"
"strings"
"testing"
@ -21,8 +20,6 @@ func TestPrepareEmailNotEU(t *testing.T) {
const apiKey = "mg-api-key"
const sendingDomain = "sending.example.com"
const serverDomain = "server.example.com"
const port = 1234
serverDomainWithPort := serverDomain + ":" + fmt.Sprint(port)
const recipient = auth.Email("recipient@example.com")
const token = auth.VerifyTokenString("abcd1234abcd1234abcd1234abcd1234")
@ -34,7 +31,7 @@ func TestPrepareEmailNotEU(t *testing.T) {
"MAILGUN_SERVER_DOMAIN": serverDomain,
}
m := Mail{port, &TestEnv{env}}
m := Mail{&TestEnv{env}}
mg, sender, subject, text, html, err := m.prepareMessage(token)
@ -58,12 +55,12 @@ func TestPrepareEmailNotEU(t *testing.T) {
t.Errorf("Expected subject to contain %s. Got: %s", serverDomain, subject)
}
if !strings.Contains(text, serverDomainWithPort) {
t.Errorf("Expected text to contain %s. Got: %s", serverDomainWithPort, text)
if !strings.Contains(text, serverDomain) {
t.Errorf("Expected text to contain %s. Got: %s", serverDomain, text)
}
if !strings.Contains(html, serverDomainWithPort) {
t.Errorf("Expected html to contain %s. Got: %s", serverDomainWithPort, html)
if !strings.Contains(html, serverDomain) {
t.Errorf("Expected html to contain %s. Got: %s", serverDomain, html)
}
}
@ -75,8 +72,6 @@ func TestPrepareEmailEU(t *testing.T) {
const recipient = auth.Email("recipient@example.com")
const token = auth.VerifyTokenString("abcd1234abcd1234abcd1234abcd1234")
const port = 1234
env := map[string]string{
"MAILGUN_SENDING_DOMAIN_IS_EU": "true",
"ACCOUNT_VERIFICATION_MODE": "EmailVerify",
@ -85,7 +80,7 @@ func TestPrepareEmailEU(t *testing.T) {
"MAILGUN_SERVER_DOMAIN": serverDomain,
}
m := Mail{port, &TestEnv{env}}
m := Mail{&TestEnv{env}}
mg, _, _, _, _, err := m.prepareMessage(token)

View file

@ -65,11 +65,6 @@ func main() {
// The port that the sync server serves from.
internalPort := 8090
// The port that the webserver (Caddy recommended), which reverse proxies to
// the sync server, should use to serve to the outside world. This will be
// used for links in emails.
externalPort := 8091
srv := server.Init(&auth.Auth{}, &store, &e, &mail.Mail{externalPort, &e}, internalPort)
srv := server.Init(&auth.Auth{}, &store, &e, &mail.Mail{&e}, internalPort)
srv.Serve()
}

View file

@ -74,7 +74,7 @@ class WalletSync():
if local:
BASE_URL = 'http://localhost:8090'
else:
BASE_URL = 'https://dev.lbry.id:8091'
BASE_URL = 'https://dev.lbry.id'
# Avoid confusion. I sometimes forget, at any rate.
print ("Connecting to Wallet API at " + BASE_URL)