-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.ex
56 lines (46 loc) · 1.38 KB
/
router.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
defmodule HelloWeb.Router do
use HelloWeb, :router
import Plugs.Admin
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
# Pipelines
# Creating New Pipelines
# https://hexdocs.pm/phoenix/routing.html#pipelines
pipeline :admin_checks do
plug :ensure_authenticated_user
plug :ensure_user_is_admin
end
scope "/", HelloWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
get "/hello", HelloController, :index
get "/hello/:messenger", HelloController, :show
# Nested resources:
# https://hexdocs.pm/phoenix/routing.html#nested-resources
resources "/users", UserController, only: [:index] do
resources "/posts", PostController
end
end
# Scoped Routes
# https://hexdocs.pm/phoenix/routing.html#scoped-routes
scope "/admin", HelloWeb.Admin, as: :admin do
pipe_through [:browser, :admin_checks]
resources "/users", UserController
end
# Forward:
# Send all requests that start with a particular path to a particular plug
# https://hexdocs.pm/phoenix/routing.html#forward
forward "/jobs", BackgroundJob.Plug
# Other scopes may use custom stacks.
scope "/api", HelloWeb do
pipe_through :api
end
end