diff --git a/config/deploy.yml b/config/deploy.yml index 5550c317e..5d2f52e01 100644 --- a/config/deploy.yml +++ b/config/deploy.yml @@ -28,6 +28,7 @@ env: - SMTP_USERNAME - SMTP_PASSWORD clear: + BASE_URL: https://fizzy.example.com # The public URL of your Fizzy instance MAILER_FROM_ADDRESS: support@example.com # The email "from" address that Fizzy sends email from SMTP_ADDRESS: mail.example.com # The SMTP server you'll use to send email MULTI_TENANT: false # Set to true to allow multiple accounts to sign up diff --git a/config/environments/production.rb b/config/environments/production.rb index 173318fe3..5faa69ac0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -21,6 +21,17 @@ Rails.application.configure do } end + # Base URL for links in emails and other external references. + # Set BASE_URL to your instance's public URL (e.g., https://fizzy.example.com) + if base_url = ENV["BASE_URL"].presence + uri = URI.parse(base_url) + url_options = { host: uri.host, protocol: uri.scheme } + url_options[:port] = uri.port if uri.port != uri.default_port + + routes.default_url_options = url_options + config.action_mailer.default_url_options = url_options + end + # Code is not reloaded between requests. config.enable_reloading = false diff --git a/docs/docker-deployment.md b/docs/docker-deployment.md index b83067522..03b4d9c8b 100644 --- a/docs/docker-deployment.md +++ b/docs/docker-deployment.md @@ -90,6 +90,15 @@ Less commonly, you might also need to set some of the following: You can find out more about all these settings in the [Rails Action Mailer documentation](https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration). +#### Base URL + +Fizzy needs to know the public URL of your instance so it can generate correct links in certain situations (like when sending emails). +Set `BASE_URL` to the full URL where your Fizzy instance is accessible: + +```sh +docker run --environment BASE_URL=https://fizzy.example.com ... +``` + #### VAPID keys Fizzy can also send Web Push notifications. @@ -153,6 +162,7 @@ services: environment: - SECRET_KEY_BASE=abcdefabcdef - TLS_DOMAIN=fizzy.example.com + - BASE_URL=https://fizzy.example.com - MAILER_FROM_ADDRESS=fizzy@example.com - SMTP_ADDRESS=mail.example.com - SMTP_USERNAME=user diff --git a/docs/kamal-deployment.md b/docs/kamal-deployment.md index 9f90d1c20..19aa208c8 100644 --- a/docs/kamal-deployment.md +++ b/docs/kamal-deployment.md @@ -33,6 +33,7 @@ We've added comments to that file to highlight what each setting needs to be, bu - `servers/web`: Enter the hostname of the server you're deploying to here. This should be an address that you can access via `ssh`. - `ssh/user`: If you access your server a `root` you can leave this alone; if you use a different user, set it here. - `proxy/ssl` and `proxy/host`: Kamal can set up SSL certificates for you automatically. To enable that, set the hostname again as `host`. If you don't want SSL for some reason, you can set `ssl: false` to turn it off. +- `env/clear/BASE_URL`: The public URL of your Fizzy instance (e.g., `https://fizzy.example.com`). Used when generating links. - `env/clear/MAILER_FROM_ADDRESS`: This is the email address that Fizzy will send emails from. It should usually be an address from the same domain where you're running Fizzy. - `env/clear/SMTP_ADDRESS`: The address of an SMTP server that you can send email through. You can use a 3rd-party service for this, like Sendgrid or Postmark, in which case their documentation will tell you what to use for this. - `env/clear/MULTI_TENANT`: Set to `true` if you want to allow multiple accounts to sign up on your server (by default, Fizzy will allow you to create a single account).