zhulinpinyu / zhulinpinyu.github.io

Blog
http://blog.zhulinpinyu.com
Apache License 2.0
2 stars 0 forks source link

《Programming Phoenix 1.4》 Notes #13

Open zhulinpinyu opened 5 years ago

zhulinpinyu commented 5 years ago

“Although applications usually have a single endpoint, Phoenix doesn’t limit the number of endpoints your application can have. For example, you could have your main application endpoint running on port 80 (HTTP) and 443 (HTTPS), as well as a specific admin endpoint running on a special port—let’s say 8080 (HTTPS)—with specific characteristics and security constraints.”

phoenix 可以设置多个入口


pipeline ​:browser​ ​do​
​  plug ​:accepts​, [​"​​html"​]
​  plug ​:fetch_session​
​  plug ​:fetch_flash​
​  plug ​:protect_from_forgery​
​  plug ​:put_secure_browser_headers​
​​end​

pipeline就是一个plug的集合


​​iex> import​ Ecto.Changeset
​Ecto.Changeset
​
​​iex>​ changeset = put_change(changeset, ​:username​, ​"​​ericmj"​)
​%Ecto.Changeset{changes: %{username: "ericmj"}, ...}
​
​​iex>​ changeset.changes
​%{username: "ericmj"}
​
​​iex>​ get_change(changeset, ​:username​)
​"ericmj"

Ecto.Changeset 值得一试之 put_change和get_change


有两种类型的plugs

There are two kinds of plugs: module plugs and function plugs. A function plug is a single function. A module plug is a module that provides two functions with some configuration details. Either way, they work the same.

函数级别的plug就是一个函数,module级别的plug 是一个module 额外定义两个函数和一些config