Current section

Files

Jump to
scales_cms lib scales_cms_web router.ex
Raw

lib/scales_cms_web/router.ex

defmodule ScalesCmsWeb.Router do
use ScalesCmsWeb, :router
import ScalesCmsWeb.CmsRouter
import ScalesCmsWeb.UserAuth
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {ScalesCmsWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
end
pipeline :api do
plug :accepts, ["json"]
plug(ScalesCmsWeb.Plugs.ApiVersion)
end
pipeline :authenticated_api do
plug(:accepts, ["json"])
plug(ScalesCmsWeb.Plugs.JwtAuthentication)
end
scope "/", ScalesCmsWeb do
pipe_through :browser
get "/", PageController, :home
if Application.compile_env(:scales_cms, :dev_mode) do
live "/users/log_in", DevEnv.UserLoginLive
end
post "/users/log_in", UserSessionController, :create
end
# UI state persistence endpoints (called by LiveView hooks via fetch)
scope "/ui", ScalesCmsWeb do
pipe_through [:browser, :require_authenticated_user]
end
scope "/" do
cms_assets()
end
scope "/" do
pipe_through [:browser, :require_authenticated_user]
cms_admin(on_mount: [{ScalesCmsWeb.UserAuth, :ensure_authenticated}]) do
# custom routes
end
end
scope "/api" do
pipe_through([:api, :authenticated_api])
api_public()
end
# Enable LiveDashboard and Swoosh mailbox preview in development
if Application.compile_env(:scales_cms, :dev_routes) do
# If you want to use the LiveDashboard in production, you should put
# it behind authentication and allow only admins to access it.
# If your application does not have an admins-only section yet,
# you can use Plug.BasicAuth to set up some basic authentication
# as long as you are also using SSL (which you should anyway).
import Phoenix.LiveDashboard.Router
scope "/dev" do
pipe_through :browser
live_dashboard "/dashboard", metrics: ScalesCmsWeb.Telemetry
forward "/mailbox", Plug.Swoosh.MailboxPreview
end
end
end