I'm currently at learning Elixir Phoenix framework. I stuck at https://hexdocs.pm/phoenix/routing.html#forward now, it's about how to use forward command.
It's written there, that it's not neccessary to learn about Plugs now, so if I want to try out that forward command I can just copy their implementation of Plug into my application. But where exactly? I tried to search it out and tried to use what I found, but I am doing something wrong.
That's the scope from my .\lib\hello_web\router.ex file:
scope "/", HelloWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
forward "/jobs", BackgroundJob.Plug, name: "Hello, Phoenix"
end
And that is the code for a Plug:
defmodule BackgroundJob.Plug do
def init(opts), do: opts
def call(conn, opts) do
conn
|> Plug.Conn.assign(:name, Keyword.get(opts, :name, "Background Job"))
|> BackgroundJob.Router.call(opts)
end
end
defmodule BackgroundJob.Router do
use Plug.Router
plug :match
plug :dispatch
get "/", do: send_resp(conn, 200, "Welcome to #{conn.assigns.name}")
get "/active", do: send_resp(conn, 200, "5 Active Jobs")
get "/pending", do: send_resp(conn, 200, "3 Pending Jobs")
match _, do: send_resp(conn, 404, "Not found")
end
I supposed to know almost nothing about Plugs and Phoenix at all at this point, so it is probably something obvious, but I really stuck there for hours. Can anyone help me to find out where to place that code?