How to add a Plug in Elixir / Phoenix before the Router? -
is there way insert plug run prior router selecting controller/action? i've got app redirect root path specific subdomains, regardless of current path on domains. so:
sub.myapp.com/foo/bar
should redirect sub.myapp.com/
but, default, router says there no path /foo/bar
, halts execution of plugs, meaning never hits redirect.
is there way insert plug prior router choosing action/controller?
(note: i'm pretty sure can handle case a catch-all route, i'm curious if there's better way.)
your router called explicitly in lib/my_app/endpoint.ex
. can add plugs in file before then.
you can write plug handles redirects , halt connection before router called.
defmodule hellophoenix.endpoint use phoenix.endpoint, otp_app: :hello_phoenix plug plug.requestid plug plug.logger ... plug customredirectplug # add plug here plug hellophoenix.router end
Comments
Post a Comment