diff --git a/.env.production.sample b/.env.production.sample index 4ee2faa..f08954d 100644 --- a/.env.production.sample +++ b/.env.production.sample @@ -4,7 +4,9 @@ ## Values after "=" sign are taken as-is, so don't use double quotes for strings. ## Base URL of your asciinema web app instance -BASE_URL=http://localhost:3000 +URL_SCHEME=http +URL_HOST=localhost +URL_PORT=3000 ## Base secret key for signing cookies etc. ## Run `docker-compose run --rm web bundle exec rake secret` diff --git a/config/application.rb b/config/application.rb index 4fd5aa3..bdad471 100644 --- a/config/application.rb +++ b/config/application.rb @@ -67,7 +67,11 @@ module Asciinema ) end - config.action_mailer.default_url_options = { protocol: CFG.scheme, host: CFG.hostname_with_port } + config.action_mailer.default_url_options = { + protocol: CFG.url_scheme, + host: CFG.url_host, + port: CFG.url_port + } if CFG.smtp_settings config.action_mailer.smtp_settings = CFG.smtp_settings diff --git a/config/cfg.rb b/config/cfg.rb index 88dbf31..ac3118d 100644 --- a/config/cfg.rb +++ b/config/cfg.rb @@ -4,7 +4,9 @@ module Asciinema class Configuration include Virtus.model - attribute :base_url, String, default: 'http://localhost:3000' + attribute :url_scheme, String, default: "http" + attribute :url_host, String, default: "localhost" + attribute :url_port, Integer, default: 3000 attribute :bugsnag_api_key, String attribute :aws_access_key_id, String attribute :aws_secret_access_key, String @@ -28,31 +30,12 @@ module Asciinema end end - def scheme - URI.parse(base_url).scheme - end - - def hostname - URI.parse(base_url).hostname - end - - def hostname_with_port - uri = URI.parse(base_url) - hwp = uri.hostname - - if uri.port != uri.default_port - hwp = "#{hwp}:#{uri.port}" - end - - hwp - end - def ssl? - scheme == 'https' + url_scheme == 'https' end def smtp_from_address - super || "asciinema " + super || "asciinema " end end end diff --git a/config/prod.exs b/config/prod.exs index 70a9257..059810f 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -13,7 +13,9 @@ use Mix.Config # which you typically run after static files are built. config :asciinema, Asciinema.Endpoint, http: [port: {:system, "PORT"}], - url: [scheme: "https", host: "asciinema.org", port: 443], + url: [scheme: System.get_env("URL_SCHEME") || "https", + host: System.get_env("URL_HOST") || "asciinema.org", + port: String.to_integer(System.get_env("URL_PORT") || "443")], cache_static_manifest: "priv/static/manifest.json" # Do not print debug messages in production