diff --git a/README.md b/README.md index 62550cb..6d0dcc0 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,6 @@ for /f "delims=" %%i in ('path\to\scoreboard\bin\today.bat') do set EVENT_DATE=% set EXPLORER_REMOTE_HTTP_BASE_PATH=/results/%EVENT_DATE% ``` - ## Customizing explorer colors Explorer can be configured to use a custom color scheme to match the club website @@ -178,6 +177,8 @@ The following environment variables need to be manually set: Additionally, you can optionally set the following: * `EXPLORER_COLORS` (path, optional) - Path to a CSV file with the custom explorer color palette. +* `EXPLORER_DEFAULT_PAGE` (string, optional) - The page explorer redirects to from its root path + (one of `event`, `pax`, `raw`, `runs`, `groups`, or `cones`, defaults to `event`) * `ANNOUNCE_FONT_SIZE` (float, optional) - /announce endpoint font size. * `TV_FONT_SIZE` (float, optional) - /tv endpoint font size. * `TV_REFRESH_INTERVAL` (integer, optional) - Sets how long /tv displays a page of diff --git a/config/runtime.exs b/config/runtime.exs index 2e8ca6a..01a3665 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -24,6 +24,7 @@ if config_env() != :test do root: System.get_env("EXPLORER_REMOTE_FTP_BASE_DIR", System.get_env("LIVE_FTP_PATH", "/")) ], explorer_remote_http_base_path: System.get_env("EXPLORER_REMOTE_HTTP_BASE_PATH", "/"), + explorer_default_page: parse_explorer_page!(System.get_env("EXPLORER_DEFAULT_PAGE", "event")), explorer_colors: explorer_colors, mj_dir: System.get_env("MJ_DIR", "c:/mjtiming"), mj_debounce_interval: String.to_integer(System.get_env("MJ_DEBOUNCE_INTERVAL", "1000")), diff --git a/config/test.exs b/config/test.exs index 5c923cf..19e8cb4 100644 --- a/config/test.exs +++ b/config/test.exs @@ -22,7 +22,8 @@ config :conecerto_scoreboard, Conecerto.Scoreboard, watcher: nil, uploader: nil, event_date: "2023_01_01", - explorer_colors: %{} + explorer_colors: %{}, + explorer_default_page: "event" # Print only warnings and errors during test config :logger, level: :warning diff --git a/lib/conecerto_scoreboard/config_utils.ex b/lib/conecerto_scoreboard/config_utils.ex index 9d8c6b7..32e2cb1 100644 --- a/lib/conecerto_scoreboard/config_utils.ex +++ b/lib/conecerto_scoreboard/config_utils.ex @@ -6,6 +6,14 @@ defmodule Conecerto.Scoreboard.ConfigUtils do end end + def parse_explorer_page!(s) do + if Enum.member?(~w(event pax raw groups runs cones), s) do + s + else + raise "#{s} is not a valid explorer page" + end + end + def generate_secret_key_base() do for _ <- 1..64, into: "" do <> diff --git a/lib/conecerto_scoreboard/uploader.ex b/lib/conecerto_scoreboard/uploader.ex index d21a4a0..2684876 100644 --- a/lib/conecerto_scoreboard/uploader.ex +++ b/lib/conecerto_scoreboard/uploader.ex @@ -10,14 +10,16 @@ defmodule Conecerto.Scoreboard.Uploader do @endpoint Conecerto.ScoreboardWeb.Endpoint - @htaccess ~s( + @htaccess_template ~s( RewriteEngine On +RewriteBase <%= base_path %> + # Index redirects to event page -RewriteRule "^$" event [R=302,L] +RewriteRule "^$" <%= default_page %> [R=302,L] # Deny Phoenix live reload stuff that doesn't exist -RewriteRule "^phoenix/live_reload/frame$" event [R=404,L] +RewriteRule "^phoenix/live_reload/frame$" <%= default_page %> [R=404,L] # Serve gzip compressed files. RewriteCond "%{HTTP:Accept-Encoding}" "gzip" @@ -36,7 +38,8 @@ RewriteRule "\.html.gz$" "-" [T=text/html,E=no-gzip:1] def start_link(_) do args = %{ client_args: Scoreboard.config(:explorer_remote_ftp), - base_path: Scoreboard.config(:explorer_remote_http_base_path) + base_path: Scoreboard.config(:explorer_remote_http_base_path), + default_page: Scoreboard.config(:explorer_default_page) } GenServer.start_link(__MODULE__, args) @@ -55,9 +58,15 @@ RewriteRule "\.html.gz$" "-" [T=text/html,E=no-gzip:1] @impl true def handle_continue(:upload_assets, state) do + htaccess = + EEx.eval_string(@htaccess_template, + base_path: state.base_path, + default_page: state.default_page + ) + with {:ok, client} <- FTP.open(state.client_args), :ok <- FTP.mkdir(client, "/"), - :ok <- FTP.send_bin(client, @htaccess, "/.htaccess"), + :ok <- FTP.send_bin(client, htaccess, "/.htaccess"), :ok <- send_static(client, "/favicon.ico"), :ok <- FTP.mkdir(client, "assets"), :ok <- send_static(client, "/assets/app.css"),