You did not indicate why you want to do this, so I can give a general answer. If you have a specific use case, then there may be a better solution.
You can do this by adding an additional plug to the router, which stores options in the conn private storage:
plug :opts_to_private
defp opts_to_private(conn, opts) do
put_private(conn, :my_app_opts, opts)
end
This will then be available on your routes with conn.private.my_app_opts
:
get "/" do
conn.private.my_app_opts
|> IO.inspect
conn
|> send_resp(201, "world")
end
defoverridable/1, , :
defp dispatch(conn, opts) do
conn = put_private(conn, :my_app_opts, opts)
super(conn, opts)
end
, opts_to_private
cleaner.