有没有一种方法可以仅在一条路线上安装Phoenix插头? [英] Is there a way to have a Phoenix Plug just for one route?

查看:89
本文介绍了有没有一种方法可以仅在一条路线上安装Phoenix插头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在凤凰城,我的路线如下:

In Phoenix I have my routes as follow :

  scope "/", ManaWeb do
    pipe_through [:browser, :auth]
    get "/register",  RegistrationController, :new
    post "/register", RegistrationController, :register
  end

但是我想为最后一条路线(POST)设置一个插头.

However I would like to set a Plug for the last route (POST).

我将如何使用当前的工具进行处理?

How would I go about that with current tools ?

推荐答案

Phoenix.Router.pipeline/2

每次调用pipe_through/1时,新管道都会附加到先前给定的管道上.

Every time pipe_through/1 is called, the new pipelines are appended to the ones previously given.

也就是说,这可以工作:

That said, this would work:

scope "/", ManaWeb do
  pipe_through [:browser, :auth]
  get "/register",  RegistrationController, :new

  pipe_through :post_plug
  post "/register", RegistrationController, :register
end

这篇关于有没有一种方法可以仅在一条路线上安装Phoenix插头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆