fireproofsocks

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

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

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

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48475 226
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement