I’m trying to create an API in Phoenix and this is how I’ve created my Phoenix app:
$ mix phx.new my_app --no-html --no-ecto --no-webpack --no-dashboard
However I keep getting this debug info after running the server
[info] GET /phoenix/live_reload/socket/websocket
[debug] ** (Phoenix.Router.NoRouteError) no route found for GET /phoenix/live_reload/socket/websocket (MyAppWeb.Router)
(my_app 0.1.0) lib/phoenix/router.ex:402: MyAppWeb.Router.call/2
(my_app 0.1.0) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.plug_builder_call/2
(my_app 0.1.0) lib/plug/debugger.ex:136: MyAppWeb.Endpoint."call (overridable 3)"/2
(my_app 0.1.0) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.call/2
(phoenix 1.5.9) lib/phoenix/endpoint/cowboy2_handler.ex:65: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy 2.9.0) /Users/burak/git/my_app/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.9.0) /Users/burak/git/my_app/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3
(cowboy 2.9.0) /Users/burak/git/my_app/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3
(stdlib 3.14.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
How can I stop this?
This is my endpoint.ex
, not sure whether that is related to this file anyway, just pasting.
Let me know if you need to see any other specific file.
defmodule MyAppWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :my_app
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
@session_options [
store: :cookie,
key: "_my_app_key",
signing_salt: "ZEYFSyPp"
]
# socket "/socket", MyAppWeb.UserSocket,
# websocket: true,
# longpoll: false
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :my_app,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
plug Phoenix.CodeReloader
end
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug MyAppWeb.Router
end
router.ex
defmodule MyAppWeb.Router do
use MyAppWeb, :router
pipeline :api do
plug :accepts, ["json"]
plug :auth
end
scope "/api", MyAppWeb do
pipe_through :api
get "/token", AccountsController, :token
get "/accounts", AccountsController, :index
end
defp auth(conn, _opts) do
username = System.fetch_env!("USERNAME")
password = System.fetch_env!("PASSWORD")
Plug.BasicAuth.basic_auth(conn, username: username, password: password)
end
end