router.ex 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. defmodule ToyWeb.Router do
  2. use ToyWeb, :router
  3. pipeline :browser do
  4. plug :accepts, ["html"]
  5. plug :fetch_session
  6. plug :fetch_live_flash
  7. plug :put_root_layout, {ToyWeb.LayoutView, :root}
  8. plug :protect_from_forgery
  9. plug :put_secure_browser_headers
  10. end
  11. pipeline :api do
  12. plug :accepts, ["json"]
  13. end
  14. scope "/", ToyWeb do
  15. pipe_through :browser
  16. live "/", PageLive, :index
  17. end
  18. # Other scopes may use custom stacks.
  19. # scope "/api", ToyWeb do
  20. # pipe_through :api
  21. # end
  22. # Enables LiveDashboard only for development
  23. #
  24. # If you want to use the LiveDashboard in production, you should put
  25. # it behind authentication and allow only admins to access it.
  26. # If your application does not have an admins-only section yet,
  27. # you can use Plug.BasicAuth to set up some basic authentication
  28. # as long as you are also using SSL (which you should anyway).
  29. if Mix.env() in [:dev, :test] do
  30. import Phoenix.LiveDashboard.Router
  31. scope "/" do
  32. pipe_through :browser
  33. live_dashboard "/dashboard", metrics: ToyWeb.Telemetry
  34. end
  35. end
  36. # Enables the Swoosh mailbox preview in development.
  37. #
  38. # Note that preview only shows emails that were sent by the same
  39. # node running the Phoenix server.
  40. if Mix.env() == :dev do
  41. scope "/dev" do
  42. pipe_through :browser
  43. forward "/mailbox", Plug.Swoosh.MailboxPreview
  44. end
  45. end
  46. end