I’m working on a custom plug to handle some signin logic for a Phoenix app. Knowing that Phoenix is built on plugs, I thought it might be nice to have this plug handle everything related to this particular request since it felt somewhat arbitrary and redundant to send the request to a controller. In my router I’ve tried a couple things:
scope "/some/path" do pipe_through :api forward "/", MyApp.CustomPlug end
And the unscoped “naked” version of just doing this:
forward "/some/path", MyApp.CustomPlug
Those DO work, but the
forward macro will forward EVERYTHING to the plug – GET’s, POST’s, as well as any deeper routes built off of the given one, e.g.
I like the interface of just being to tie the plug to one route and let it handle everything, but is this misunderstanding how the plug should be used? (I may package this plug separately for use with other apps). If this is a legitimate way to use the plug, how would I restrict it to only respond to POST request, and how would I tell it to ignore any other paths other than the base path?
Of course, I put the plug in a pipeline and handle everything there, but it seems a bit redundant to rely on a pipeline for this. What might be a cleaner way to accomplish this?