Hello, everyone. Got stuck with a strange error again …
[info] GET /js/app.js
[info] GET /css/app.css
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /js/app.js (Web.Router)
(web) lib/web/router.ex:1: Web.Router.__match_route__/4
(web) lib/phoenix/router.ex:303: Web.Router.call/2
(web) lib/web/endpoint.ex:1: Web.Endpoint.plug_builder_call/2
(web) lib/plug/debugger.ex:99: Web.Endpoint."call (overridable 3)"/2
(web) lib/web/endpoint.ex:1: Web.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /css/app.css (Web.Router)
(web) lib/web/router.ex:1: Web.Router.__match_route__/4
(web) lib/phoenix/router.ex:303: Web.Router.call/2
(web) lib/web/endpoint.ex:1: Web.Endpoint.plug_builder_call/2
(web) lib/plug/debugger.ex:99: Web.Endpoint."call (overridable 3)"/2
(web) lib/web/endpoint.ex:1: Web.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
endpoint.ex
defmodule Web.Endpoint do
use Phoenix.Endpoint, otp_app: :web
socket("/socket", Web.UserSocket)
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug(
Plug.Static,
at: "/",
from: :web,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
)
# ...
plug(Web.Router)
end
Shouldn’t plug static match first? Why is Web.Router
even called?
I also get this strange error if
== Compilation error in file lib/web/views/session_view.ex ==
** (CompileError) lib/web/views/session_view.ex:2: module Web.Router.Helpers is not loaded and could not be found
expanding macro: Web.__using__/1
lib/web/views/session_view.ex:2: Web.SessionView (module)
(elixir) expanding macro: Kernel.use/2
lib/web/views/session_view.ex:2: Web.SessionView (module)
(elixir) lib/kernel/parallel_compiler.ex:198: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
if I import Web.Router.Helpers
in a module that doesn’t use Web
.
So the problem is probably somewhere in the router:
defmodule Web.Router do
use Web, :router
pipeline :browser do
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_flash)
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
end
scope "/", Web do
pipe_through(:browser)
get("/", PageController, :index)
get("/explore", PageController, :explore)
end
end
or web.ex
defmodule Web do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
This can be used in your application as:
use Web, :controller
use Web, :view
The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused
on imports, uses and aliases.
Do NOT define functions inside the quoted expressions
below. Instead, define any helper function in modules
and import those modules here.
"""
def controller do
quote do
use Phoenix.Controller
import Plug.Conn
import Web.Router.Helpers
import Web.Gettext
end
end
def view do
quote do
use Phoenix.View, root: "lib/web/templates"
# Import convenience functions from controllers
import Phoenix.Controller, only: [get_flash: 2, view_module: 1]
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Web.Router.Helpers
import Web.ErrorHelpers
import Web.Gettext
end
end
def router do
quote do
use Phoenix.Router
import Plug.Conn
import Phoenix.Controller
end
end
def channel do
quote do
use Phoenix.Channel
import Web.Gettext
end
end
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end