phoenix项目中的router.ex中的“管道”的定义在哪里?

发布于 2025-02-12 05:01:13 字数 705 浏览 2 评论 0原文

我正在通过VScode阅读Phoenix项目。 pipeline范围router.ex.ex文件中的含义是什么。

无法通过vscode找到参考。它缝制它们不是精灵语言的关键字。他们是什么?

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, {HelloWeb.LayoutView, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
    plug HelloWeb.Plugs.Locale, "en"
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", HelloWeb do
    pipe_through :browser

    get "/", PageController, :index
    get "/hello", HelloController, :index
    get "/hello/:messenger", HelloController, :show
  end

I am reading phoenix project through vscode. What's the meaning of pipeline,scope in the router.ex file.

It can't be found reference by vscode. It seams that they are not keywords of elixir language. What's are they?

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_live_flash
    plug :put_root_layout, {HelloWeb.LayoutView, :root}
    plug :protect_from_forgery
    plug :put_secure_browser_headers
    plug HelloWeb.Plugs.Locale, "en"
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", HelloWeb do
    pipe_through :browser

    get "/", PageController, :index
    get "/hello", HelloController, :index
    get "/hello/:messenger", HelloController, :show
  end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2025-02-19 05:01:13

它们是宏:在汇编过程中,他们将评估并创建常规代码(即宏是“创建代码的代码”)。宏可以帮助您定义简单的接口并迅速生成许多乏味的代码,但是它们绝对难以调试和关注编辑器。

在这种情况下,这些宏可以方便地定义特定域的语言(DSL),该语言提供了一种表达方式来定义路由和中间件。

可以在您的任何代码或依赖项中定义宏。查找defmacro关键字。在这种情况下,它们在Phoenix 路由器模块中定义。

They are macros: during compilation they will evaluate and create regular code (i.e. macros are "code that creates code"). Macros can help you define simple interfaces and quickly generate lots of tedious code, but they are definitely more difficult to debug and follow in an editor.

In this case, these macros are handy for defining a domain specific language (DSL) that offers an expressive way to define routes and middleware.

Macros can be defined in any of your code or in your dependencies. Look for the defmacro keyword. In this case, they're defined within the Phoenix Router module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文