Replace Endpoint host and port by base url

This commit is contained in:
Alex
2024-04-14 23:58:14 +02:00
parent 6a16e91de9
commit dcc0bf4e33
5 changed files with 96 additions and 70 deletions

View File

@@ -1,5 +1,10 @@
BASE_URL=http://localhost:4000
# SAME_SITE_COOKIE=Lax
# SECURE_COOKIE=false
DATABASE_URL=postgres://claper:claper@db:5432/claper
SECRET_KEY_BASE=0LZiQBLw4WvqPlz4cz8RsHJlxNiSqM9B48y4ChyJ5v1oA0L/TPIqRjQNdPZN3iEG # Generate with `mix phx.gen.secret`
SECRET_KEY_BASE=0LZiQBLw4WvqPlz4cz8RsHJlxNiSqM9B48y4ChyJ5v1oA0L/TPIqRjQNdPZN3iEG # Generate with `mix phx.gen.secret`
# ⚠️ Don't use this exact value for SECRET_KEY_BASE or someone would be able to sign a cookie with user_id=1 and log in as the admin!
# Storage configuration
@@ -31,9 +36,4 @@ MAIL_FROM_NAME=Claper
# Claper configuration
#ENABLE_ACCOUNT_CREATION=true
#GS_JPG_RESOLUTION=300x300
# Network configuration
ENDPOINT_PORT=4000
ENDPOINT_HOST=localhost
#GS_JPG_RESOLUTION=300x300

View File

@@ -1,5 +1,7 @@
## v2.0.0
### Features
- Add dynamic layout in the manager view
- Add quick event feature
- Add question feature
@@ -9,8 +11,10 @@
- Add language switcher in user settings
- Add tour guide for new users
- Add headers to exported CSV in reports
- Add the ability to embed attendees room in an iframe
- Add spanish locale (#84) (@eduproinf)
### Fixes and improvements
- Improve Docker image to support both ARM and AMD64 architecture
- Change date picker for a more user-friendly one
- Upgrade Ecto, Phoenix and LiveView
@@ -18,6 +22,8 @@
- Fix average voters stats
- Fix some UI/UX issues
- Remove end date for events
- Replace `ENDPOINT_PORT` and `ENDPOINT_HOST` with `BASE_URL` environment variable
- Add `SAME_SITE_COOKIE` and `SECURE_COOKIE` environment variables
## v1.7.0

View File

@@ -41,8 +41,18 @@ case secret_key_base do
nil
end
endpoint_host = get_var_from_path_or_env(config_dir, "ENDPOINT_HOST", "localhost")
endpoint_port = get_int_from_path_or_env(config_dir, "ENDPOINT_PORT", 4000)
site_url = get_var_from_path_or_env(config_dir, "SITE_URL", "http://localhost:4000")
base_url = get_var_from_path_or_env(config_dir, "BASE_URL")
if !base_url do
raise "BASE_URL configuration option is required. See https://docs.claper.co/configuration.html#production-docker"
end
base_url = URI.parse(base_url)
if base_url.scheme not in ["http", "https"] do
raise "BASE_URL must start with `http` or `https`. Currently configured as `#{System.get_env("BASE_URL")}`"
end
max_file_size = get_int_from_path_or_env(config_dir, "MAX_FILE_SIZE_MB", 15)
@@ -67,6 +77,11 @@ aws_access_key_id = get_var_from_path_or_env(config_dir, "AWS_ACCESS_KEY_ID", ni
aws_secret_access_key = get_var_from_path_or_env(config_dir, "AWS_SECRET_ACCESS_KEY", nil)
aws_region = get_var_from_path_or_env(config_dir, "AWS_REGION", nil)
same_site_cookie = get_var_from_path_or_env(config_dir, "SAME_SITE_COOKIE", "Lax")
secure_cookie =
get_var_from_path_or_env(config_dir, "SECURE_COOKIE", "false") |> String.to_existing_atom()
config :claper, Claper.Repo,
url: database_url,
ssl: db_ssl,
@@ -78,17 +93,16 @@ config :claper, Claper.Repo,
queue_target: queue_target
config :claper, ClaperWeb.Endpoint,
url: [
host: endpoint_host,
port: endpoint_port
],
url: [scheme: base_url.scheme, host: base_url.host, path: base_url.path, port: base_url.port],
http: [
ip: listen_ip,
port: port,
transport_options: [max_connections: :infinity],
protocol_options: [max_request_line_length: 8192, max_header_value_length: 8192]
],
secret_key_base: secret_key_base
secret_key_base: secret_key_base,
same_site_cookie: same_site_cookie,
secure_cookie: secure_cookie
config :claper,
enable_account_creation: enable_account_creation

View File

@@ -6,50 +6,51 @@ All configuration used by the app is stored in the `.env` file. You can find an
### Storage
Variable | Values | Default | Required | Description
--- | --- | --- | --- | ---
PRESENTATION_STORAGE | local, s3 | local | - | Define where the presentation files will be stored
PRESENTATION_STORAGE_DIR | - | priv/static (/app/uploads for Docker) | - | If `local` storage is used, this is the directory where the presentation files will be stored. Compile-time config, so you need to recompile the app if you change it (or rebuild the Docker image).
AWS_ACCESS_KEY_ID | - | - | _only for s3_ | Your AWS Access Key ID
AWS_SECRET_ACCESS_KEY | - | - | _only for s3_ | Your AWS Secret Access Key
AWS_PRES_BUCKET | - | - | _only for s3_ | The name of the bucket where the presentation files will be stored
AWS_REGION | - | - | _only for s3_ | The region where the bucket is located
| Variable | Values | Default | Required | Description |
| ------------------------ | --------- | ------------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PRESENTATION_STORAGE | local, s3 | local | - | Define where the presentation files will be stored |
| PRESENTATION_STORAGE_DIR | - | priv/static (/app/uploads for Docker) | - | If `local` storage is used, this is the directory where the presentation files will be stored. Compile-time config, so you need to recompile the app if you change it (or rebuild the Docker image). |
| AWS_ACCESS_KEY_ID | - | - | _only for s3_ | Your AWS Access Key ID |
| AWS_SECRET_ACCESS_KEY | - | - | _only for s3_ | Your AWS Secret Access Key |
| AWS_PRES_BUCKET | - | - | _only for s3_ | The name of the bucket where the presentation files will be stored |
| AWS_REGION | - | - | _only for s3_ | The region where the bucket is located |
### Mail
Variable | Values | Default | Required | Description
--- | --- | --- | --- | ---
MAIL_TRANSPORT | local, smtp, postmark | local | - | Define how the emails will be sent
MAIL_FROM | - | Claper | - | Email address used to send emails
MAIL_FROM_NAME | - | noreply@claper.co | - | Name used to send emails
SMTP_RELAY | - | - | _only for smtp_ | SMTP relay server
SMTP_USERNAME | - | - | _only for smtp_ | SMTP username
SMTP_PASSWORD | - | - | _only for smtp_ | SMTP password
SMTP_PORT | - | 25 | - | SMTP port
SMTP_TLS | always, never, if_available | always | - | SMTP TLS
SMTP_AUTH | always, never, if_available | always | - | SMTP Auth
SMTP_SSL | true, false | true | - | SMTP SSL
ENABLE_MAILBOX_ROUTE | true, false | false | - | Enable/disable route to local mailbox (`/dev/mailbox`)
MAILBOX_USER | - | - | - | Basic auth user for mailbox route
MAILBOX_PASSWORD | - | - | - | Basic auth password for mailbox route
POSTMARK_API_KEY | - | - | _only for postmark_ | Postmark API key
| Variable | Values | Default | Required | Description |
| -------------------- | --------------------------- | ----------------- | ------------------- | ------------------------------------------------------ |
| MAIL_TRANSPORT | local, smtp, postmark | local | - | Define how the emails will be sent |
| MAIL_FROM | - | Claper | - | Email address used to send emails |
| MAIL_FROM_NAME | - | noreply@claper.co | - | Name used to send emails |
| SMTP_RELAY | - | - | _only for smtp_ | SMTP relay server |
| SMTP_USERNAME | - | - | _only for smtp_ | SMTP username |
| SMTP_PASSWORD | - | - | _only for smtp_ | SMTP password |
| SMTP_PORT | - | 25 | - | SMTP port |
| SMTP_TLS | always, never, if_available | always | - | SMTP TLS |
| SMTP_AUTH | always, never, if_available | always | - | SMTP Auth |
| SMTP_SSL | true, false | true | - | SMTP SSL |
| ENABLE_MAILBOX_ROUTE | true, false | false | - | Enable/disable route to local mailbox (`/dev/mailbox`) |
| MAILBOX_USER | - | - | - | Basic auth user for mailbox route |
| MAILBOX_PASSWORD | - | - | - | Basic auth password for mailbox route |
| POSTMARK_API_KEY | - | - | _only for postmark_ | Postmark API key |
### Application
Variable | Values | Default | Required | Description
--- | --- | --- | --- | ---
ENABLE_ACCOUNT_CREATION | true, false | true | - | Enable/disable user registration
MAX_FILE_SIZE_MB | - | 15 | - | Max file size to upload in MB
GS_JPG_RESOLUTION | - | 300x300 | - | Resolution (DPI) of the JPG generated from PDF, higher resolution means bigger files but better quality
| Variable | Values | Default | Required | Description |
| ----------------------- | ----------- | ------- | -------- | ------------------------------------------------------------------------------------------------------- |
| ENABLE_ACCOUNT_CREATION | true, false | true | - | Enable/disable user registration |
| MAX_FILE_SIZE_MB | - | 15 | - | Max file size to upload in MB |
| GS_JPG_RESOLUTION | - | 300x300 | - | Resolution (DPI) of the JPG generated from PDF, higher resolution means bigger files but better quality |
| SAME_SITE_COOKIE | Lax, None | Lax | - | SameSite attribute for cookies |
| SECURE_COOKIE | true, false | false | - | Secure attribute for cookies |
## Production / Docker
You can use all local variables plus the following:
Variable | Values | Default | Required | Description
--- | --- | --- | --- | ---
DATABASE_URL | - | - | ✓ | Postgres connection string
SECRET_KEY_BASE | - | - | ✓ | Generate it with `mix phx.gen.secret`
ENDPOINT_HOST | - | localhost | - | Host used to access the app (used for url generation)
ENDPOINT_PORT | - | 80 | - | Port used to access the app (used for url generation)
PORT | - | 4000 | - | Port to listen to
| Variable | Values | Default | Required | Description |
| --------------- | ------ | ------- | -------- | ---------------------------------------------- |
| DATABASE_URL | - | - | ✓ | Postgres connection string |
| SECRET_KEY_BASE | - | - | ✓ | Generate it with `mix phx.gen.secret` |
| BASE_URL | - | - | ✓ | Base URL of the app (e.g. `https://claper.co`) |
| PORT | - | 4000 | - | Port to listen to |

View File

@@ -4,25 +4,18 @@ defmodule ClaperWeb.Endpoint do
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
@session_options (case Mix.env() do
:dev ->
[
store: :cookie,
key: "_claper_key",
signing_salt: "Tg18Y2zU",
same_site: "None",
secure: true
]
@session_options [
store: :cookie,
key: "_claper_key",
signing_salt: "Tg18Y2zU"
]
_ ->
[
store: :cookie,
key: "_claper_key",
signing_salt: "Tg18Y2zU"
]
end)
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
socket "/live", Phoenix.LiveView.Socket,
websocket: [
connect_info: [
session: {__MODULE__, :runtime_opts, []}
]
]
# Serve at "/" the static files from "priv/static" directory.
#
@@ -62,6 +55,18 @@ defmodule ClaperWeb.Endpoint do
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug(:runtime_session)
plug ClaperWeb.Router
def runtime_session(conn, _opts) do
Plug.run(conn, [{Plug.Session, runtime_opts()}])
end
def runtime_opts() do
@session_options
|> Keyword.put(:same_site, Application.get_env(:claper, __MODULE__)[:same_site_cookie])
|> Keyword.put(:secure, Application.get_env(:claper, __MODULE__)[:secure_cookie])
end
end