Search code examples
phoenix-frameworkplug

Dilemma: should I use a module plug or function plug: Phoenix


I need to reuse a function plug on different modules but it seems a bit redundant to do that. Is a module plug a better way to do this or how can I reuse the function plug?


Solution

  • A module plug is better for reusability purpose. It's best practice to always consider the scope of use of a plug before writing any plug.

    To reuse the module plug, add it to a pipeline in router.ex file