How to make a path (controller action) in Phoenix accessible from only localhost?

Or alternatively, how to call a controller action in Phoenix using a shell command? Thank you

If you want to do that it means something is wrong with the application. Controller actions are meant to be the middleman for HTTP requests, any logic should go in some modules that you can then call from controller or somewhere else (that’s MVC in general, not only Phoenix).

So to answer your question I’d extract the part that you want to call to some module and then call it from controller and from somewhere else.

As you can reach every URL from the shell…

curl http://example.com/your/route/and/id/2

Don’t forget to add formdata if necessary or set the correct method on curl. Please consult man curl to see how thats done exactly.

But still @yurko is right, you usually do not want to call into controllers/actions from the shell.

What you want to do actually is probably a well defined mix task which does the job.

1 Like