From fc8799ef8f3e667538f02414f55074b42f28d1a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Thu, 3 Feb 2022 17:48:16 +0100 Subject: [PATCH] Group public routes under a common prefix (#974) --- lib/livebook_cli/server.ex | 2 +- lib/livebook_web/router.ex | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/livebook_cli/server.ex b/lib/livebook_cli/server.ex index f7f4be047..af6f055a4 100644 --- a/lib/livebook_cli/server.ex +++ b/lib/livebook_cli/server.ex @@ -124,7 +124,7 @@ defmodule LivebookCLI.Server do defp check_endpoint_availability(base_url) do Application.ensure_all_started(:inets) - health_url = append_path(base_url, "/health") + health_url = append_path(base_url, "/public/health") case Livebook.Utils.HTTP.request(:get, health_url) do {:ok, status, _headers, body} -> diff --git a/lib/livebook_web/router.ex b/lib/livebook_web/router.ex index a08ccc50a..0cead6f48 100644 --- a/lib/livebook_web/router.ex +++ b/lib/livebook_web/router.ex @@ -20,7 +20,19 @@ defmodule LivebookWeb.Router do plug :put_secure_browser_headers end - scope "/", LivebookWeb do + # The /public namespace includes routes with no authentication. + # When exposing Livebook through an authentication proxy, this + # namespace should be configured as publicly available, in order + # for all features to work as expected. + + scope "/public", LivebookWeb do + pipe_through :browser + + get "/health", HealthController, :index + end + + # The following routes are public, but should be treated as opaque + scope "/public", LivebookWeb do pipe_through [:js_output_assets] get "/sessions/assets/:hash/*file_parts", SessionController, :show_cached_asset @@ -78,13 +90,6 @@ defmodule LivebookWeb.Router do ecto_repos: [] end - # Public URLs without authentication - scope "/", LivebookWeb do - pipe_through :browser - - get "/health", HealthController, :index - end - scope "/authenticate", LivebookWeb do pipe_through :browser