add global_assigns and public pipeline
This commit is contained in:
parent
7236ac409c
commit
83e5356e80
2 changed files with 28 additions and 1 deletions
21
lib/chiya_web/global_assigns.ex
Normal file
21
lib/chiya_web/global_assigns.ex
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
defmodule ChiyaWeb.GlobalAssigns do
|
||||||
|
import Plug.Conn
|
||||||
|
|
||||||
|
def fetch_settings(conn, _opts) do
|
||||||
|
settings = Chiya.Site.get_settings()
|
||||||
|
assign(conn, :settings, settings)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_identities(conn, _opts) do
|
||||||
|
identities = Chiya.Identities.list_identities()
|
||||||
|
assign(conn, :identities, identities)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fetch_public_channels(conn, _opts) do
|
||||||
|
channels =
|
||||||
|
Chiya.Channels.list_channels()
|
||||||
|
|> Enum.filter(fn c -> c.visibility == :public end)
|
||||||
|
|
||||||
|
assign(conn, :channels, channels)
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,6 +2,7 @@ defmodule ChiyaWeb.Router do
|
||||||
use ChiyaWeb, :router
|
use ChiyaWeb, :router
|
||||||
|
|
||||||
import ChiyaWeb.UserAuth
|
import ChiyaWeb.UserAuth
|
||||||
|
import ChiyaWeb.GlobalAssigns
|
||||||
|
|
||||||
pipeline :browser do
|
pipeline :browser do
|
||||||
plug :accepts, ["html"]
|
plug :accepts, ["html"]
|
||||||
|
@ -13,6 +14,11 @@ defmodule ChiyaWeb.Router do
|
||||||
plug :fetch_current_user
|
plug :fetch_current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pipeline :public do
|
||||||
|
plug :fetch_settings
|
||||||
|
plug :fetch_identities
|
||||||
|
end
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
plug :accepts, ["json"]
|
plug :accepts, ["json"]
|
||||||
end
|
end
|
||||||
|
@ -93,7 +99,7 @@ defmodule ChiyaWeb.Router do
|
||||||
## Public routes
|
## Public routes
|
||||||
|
|
||||||
scope "/", ChiyaWeb do
|
scope "/", ChiyaWeb do
|
||||||
pipe_through :browser
|
pipe_through [:browser, :public]
|
||||||
|
|
||||||
get "/:slug", PageController, :channel
|
get "/:slug", PageController, :channel
|
||||||
get "/", PageController, :home
|
get "/", PageController, :home
|
||||||
|
|
Loading…
Reference in a new issue