2021-03-04 05:56:28 +08:00
|
|
|
defmodule LivebookWeb.Router do
|
|
|
|
use LivebookWeb, :router
|
2021-04-15 02:10:25 +08:00
|
|
|
import Phoenix.LiveDashboard.Router
|
2021-01-08 03:55:45 +08:00
|
|
|
|
|
|
|
pipeline :browser do
|
|
|
|
plug :accepts, ["html"]
|
|
|
|
plug :fetch_session
|
2021-01-08 04:16:54 +08:00
|
|
|
plug :fetch_live_flash
|
2021-03-04 05:56:28 +08:00
|
|
|
plug :put_root_layout, {LivebookWeb.LayoutView, :root}
|
2021-01-08 03:55:45 +08:00
|
|
|
plug :protect_from_forgery
|
|
|
|
plug :put_secure_browser_headers
|
2021-04-15 20:15:56 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
pipeline :auth do
|
2021-04-08 17:41:52 +08:00
|
|
|
plug LivebookWeb.AuthPlug
|
2021-05-04 02:03:19 +08:00
|
|
|
plug LivebookWeb.UserPlug
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|
|
|
|
|
2022-02-28 20:53:33 +08:00
|
|
|
pipeline :js_view_assets do
|
2021-12-24 21:18:34 +08:00
|
|
|
plug :put_secure_browser_headers
|
|
|
|
end
|
|
|
|
|
2022-02-04 00:48:16 +08:00
|
|
|
# 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
|
2022-02-28 20:53:33 +08:00
|
|
|
pipe_through [:js_view_assets]
|
2021-12-24 21:18:34 +08:00
|
|
|
|
|
|
|
get "/sessions/assets/:hash/*file_parts", SessionController, :show_cached_asset
|
|
|
|
get "/sessions/:id/assets/:hash/*file_parts", SessionController, :show_asset
|
|
|
|
end
|
|
|
|
|
2022-02-08 04:03:25 +08:00
|
|
|
live_session :default, on_mount: [LivebookWeb.AuthHook, LivebookWeb.UserHook] do
|
2021-11-02 02:33:43 +08:00
|
|
|
scope "/", LivebookWeb do
|
|
|
|
pipe_through [:browser, :auth]
|
2021-01-08 03:55:45 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/", HomeLive, :page
|
|
|
|
live "/home/import/:tab", HomeLive, :import
|
|
|
|
live "/home/sessions/:session_id/close", HomeLive, :close_session
|
2022-01-29 04:45:04 +08:00
|
|
|
live "/home/sessions/edit_sessions/:action", HomeLive, :edit_sessions
|
2021-07-09 01:35:11 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/settings", SettingsLive, :page
|
|
|
|
live "/settings/add-file-system", SettingsLive, :add_file_system
|
2021-08-14 03:17:43 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/explore", ExploreLive, :page
|
|
|
|
live "/explore/notebooks/:slug", ExploreLive, :notebook
|
2021-07-09 01:35:11 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live "/sessions/:id", SessionLive, :page
|
|
|
|
live "/sessions/:id/shortcuts", SessionLive, :shortcuts
|
|
|
|
live "/sessions/:id/settings/runtime", SessionLive, :runtime_settings
|
|
|
|
live "/sessions/:id/settings/file", SessionLive, :file_settings
|
|
|
|
live "/sessions/:id/bin", SessionLive, :bin
|
|
|
|
get "/sessions/:id/export/download/:format", SessionController, :download_source
|
|
|
|
live "/sessions/:id/export/:tab", SessionLive, :export
|
|
|
|
live "/sessions/:id/cell-settings/:cell_id", SessionLive, :cell_settings
|
|
|
|
live "/sessions/:id/cell-upload/:cell_id", SessionLive, :cell_upload
|
|
|
|
live "/sessions/:id/delete-section/:section_id", SessionLive, :delete_section
|
|
|
|
get "/sessions/:id/images/:image", SessionController, :show_image
|
|
|
|
live "/sessions/:id/*path_parts", SessionLive, :catch_all
|
|
|
|
end
|
2021-04-15 02:10:25 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
# Public authenticated URLs that people may be directed to
|
|
|
|
scope "/", LivebookWeb do
|
|
|
|
pipe_through [:browser, :auth]
|
|
|
|
|
|
|
|
live "/import", HomeLive, :public_import
|
2022-02-04 03:26:18 +08:00
|
|
|
live "/open", HomeLive, :public_open
|
2021-11-02 02:33:43 +08:00
|
|
|
end
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|
2021-04-15 20:15:56 +08:00
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
scope "/" do
|
2021-10-16 18:23:08 +08:00
|
|
|
pipe_through [:browser, :auth]
|
|
|
|
|
2021-11-02 02:33:43 +08:00
|
|
|
live_dashboard "/dashboard",
|
|
|
|
metrics: LivebookWeb.Telemetry,
|
2021-12-25 02:05:19 +08:00
|
|
|
home_app: {"Livebook", :livebook},
|
|
|
|
ecto_repos: []
|
2021-10-16 18:23:08 +08:00
|
|
|
end
|
|
|
|
|
2021-04-15 20:15:56 +08:00
|
|
|
scope "/authenticate", LivebookWeb do
|
|
|
|
pipe_through :browser
|
|
|
|
|
|
|
|
get "/", AuthController, :index
|
|
|
|
post "/", AuthController, :authenticate
|
|
|
|
end
|
2021-01-08 03:55:45 +08:00
|
|
|
end
|