Router says plug module name is undefined when put in scope

In a Phoenix project, inside my TunnelerWeb.Router module, this is working:

forward "/foo", ReverseProxyPlug, upstream: &TunnelerWeb.Upstream.subdomain/1

And this is not:

scope "/", TunnelerWeb, host: "two." do
  forward "/foo", ReverseProxyPlug, upstream: &TunnelerWeb.Upstream.subdomain/1
end

Because of this error:

function TunnelerWeb.ReverseProxyPlug.init/1 is undefined (module TunnelerWeb.ReverseProxyPlug is not available)

Any idea why that is and how to fix it? Thank you :slightly_smiling_face:

This make the forward effectively be:

forward "/foo", TunnelerWeb.ReverseProxyPlug, upstream: &TunnelerWeb.Upstream.subdomain/1

If you don’t want the namespacing you can remove it from the scope:

scope "/", host: "two." do
  forward "/foo", ReverseProxyPlug, upstream: &TunnelerWeb.Upstream.subdomain/1
end
1 Like

Wow, awesome, thank you! Somehow I didn’t realize it was serving this purpose :sweat_smile: