Pipelines
Different with most plug based framework, plug
and plug_overridable
are bound to endpoint.
It means that this type of plugs called after route. If you need a top-level plug, you should defined it within before
block. There's a thorough example:
defmodule API do
use Maru.Router
before do
plug Plug.Static, at: "/static", from: "/my/static/path/"
end
plug Plug.Logger
plug_overridable :auth, Auth.Guest
pipeline do
plug A
end
post do
...
end
pipeline do
plug B
plug_overridable :auth, Auth.Admin
end
get :admin do
...
end
end
This router will be executed by such order:
conn
-> `Plug.Static`
-> route(:post, ["/"]) -> `Plog.Logger` -> `Auth.Guest` -> `A` -> 'endpoint block'
-> route(:get, ["admin"]) -> `Plug.Logger` -> `Auth.Admin` -> `B` -> 'endpoint block'
Updated less than a minute ago