fireproofsocks
Writing Phoenix Plugs as Separate Apps (in Umbrella)?
I’m working on a Phoenix app within an umbrella: it’s more or less one app per resource. That keeps things super-clean and tightly scoped, and it allows each app to operate independently because only the Phoenix app lists the other apps as dependencies.
What I’m wondering is how one can develop Phoenix Plugs as separate apps? Can anyone point me to existing packages available that do this? Mostly I can figure out how to set up the tests because Phoenix has a way of bootstrapping the conn Plug.Conn object. Any tips for this approach (or warnings against it)?
Thanks!
Most Liked
fireproofsocks
I got things to work without Phoenix and only with plug as a dependency – I just had to rework some of the responses, e.g.
import Plug.Conn
def send_error!(conn, msg) do
conn
|> put_status(:unauthorized)
|> Plug.Conn.put_resp_header("content-type", "application/json")
|> Plug.Conn.resp(400, ~s({"status": 400, "message": "#{msg}}"}))
|> halt
end
I just needed to look past the syntactic sugar of all the functions that are available when you import Phoenix.Controller
nivanson
What plug package? Do you mean master_proxy package? I suggest you do something like acme_bank example. I am running something similar to that in production and working just fine. Your main application router which delegates the the sub apps will be called through their specific endpoints. Here is a link to the specific file you might want to look into for guidance.
https://github.com/wojtekmach/acme_bank/blob/master/apps/master_proxy/lib/master_proxy/plug.ex
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









