2017-07-08 5 views
1

私は次のように私のweb/router.exファイル内の2つのパイプラインを定義する必要があります。フェニックスフレームワークの別のパイプライン定義でルーターパイプラインの定義を再利用するにはどうすればいいですか?

pipeline :api do 
    plug :accepts, ["json"] 
    plug :fetch_session 
    plug MyApp.Plugs.ValidatePayload 
end 

pipeline :restricted_api do 
    plug :accepts, ["json"] 
    plug :fetch_session 
    plug MyApp.Plugs.ValidatePayload 
    plug MyApp.Plugs.EnsureAuthenticated 
    plug MyApp.Plugs.EnsureAuthorized 
end 

あなたは:apiパイプラインからのステップは:restricted_apiパイプライン内で重複していることをはっきりと見ることができます。

:restricted_apiパイプラインで:apiパイプラインを再利用する方法はありますか?

私は、継承に似た何かについて考えています:

pipeline :api do 
    plug :accepts, ["json"] 
    plug :fetch_session 
    plug MyApp.Plugs.ValidatePayload 
end 

pipeline :restricted_api do 
    extend :api 
    plug MyApp.Plugs.EnsureAuthenticated 
    plug MyApp.Plugs.EnsureAuthorized 
end 

答えて

3

pipelineマクロが機能プラグを作成します。したがって、その他のプラグのような他のパイプラインではplug :pipelineと使用することができます。提供された例:

pipeline :api do 
    plug :accepts, ["json"] 
    plug :fetch_session 
    plug MyApp.Plugs.ValidatePayload 
end 

pipeline :restricted_api do 
    plug :api 
    plug MyApp.Plugs.EnsureAuthenticated 
    plug MyApp.Plugs.EnsureAuthorized 
end 
関連する問題