static_path and Plug.Static
The static_path/1
is the callback function which is defined in Phoenix.Endpoint behaviour. Look inside your YOUAPP.Endpoint
module, there is "use Phoenix.Endpoint, otp_app: :your_app_web``` at the top of module. When you look at source code for static_path/1, it actually returns "/" as a default value for script path.
Basically, Phoenix only generate the path for you and it does not know the location of your web app /priv directory.
Inside your Endpoint module, there should be a section of code like this:
plug Plug.Static,
at: "/", from: :tokenix_admin_web, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
The keyword from
which is
the file system path to read static assets from. It can be either: a string containing a file system path, an
atom representing the application name (where assets will
be served from `priv/static`), or a tuple containing the
application name and the directory to serve assets from (besides `priv/static`).
The Plug.Static module is the one serving the priv/static contents when there is a request to "/" path.
Phoenix.Router.Helpers
The Magic paths or generated paths are from Phoenix.Router.Helpers module.
Before Phoenix.Router compile, it will define helpers function first. It read your routes definitions can pass it into Phoenix.Router.Helpers.define/2 which will generated based on the controller name.
Helpers are automatically generated based on the controller name.
For example, the route:
get "/pages/:page", PageController, :show
will generate the following named helper:
MyAppWeb.Router.Helpers.page_path(conn_or_endpoint, :show, "hello")
"/pages/hello"
MyAppWeb.Router.Helpers.page_path(conn_or_endpoint, :show, "hello", some: "query")
"/pages/hello?some=query"
MyAppWeb.Router.Helpers.page_url(conn_or_endpoint, :show, "hello")
"http://example.com/pages/hello"
MyAppWeb.Router.Helpers.page_url(conn_or_endpoint, :show, "hello", some: "query")
"http://example.com/pages/hello?some=query"
It uses metaprogramming to generate helper_path code.
So the real name is helper path.
You should take a look at your YourApp, YourApp.Application", YourApp.Endpoint and YourApp.Router modules. Phoenix usually will explicitly define the configurations.