Routing issue for favicon


I have a routing issue with what looks like a favicon.ico file. The frontend is a React App running and the favicon is in that project, but I can’t see any reference for the favicon.ico inside the phoenix app. In the dev.exs config file the frontend React app is referenced (localhost port 3000 and the Phoenix app is running on port 4000);

config :platform, PlatformWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [],
front_end_host: “http://localhost:3000

But its almost as if this isn’t been seen by the Phoenix app (again, apologies, excuse my ignorance of the obvious as I’m wading through this).

The error I have is;

[error] #PID<0.680.0> running PlatformWeb.Endpoint (connection #PID<0.671.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /favicon.ico
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: 10
(cowboy 2.8.0) /Users/carl/Dev/api/deps/cowboy/src/cowboy_req.erl:815: :cowboy_req.reply/4
(plug_cowboy 2.4.1) lib/plug/cowboy/conn.ex:35: Plug.Cowboy.Conn.send_resp/4
(plug 1.11.0) lib/plug/conn.ex:410: Plug.Conn.send_resp/1
(platform 0.1.0) lib/plug/router.ex:284: PlatformWeb.PlugRouter.dispatch/2
(platform 0.1.0) lib/platform_web/plugs/plug_router.ex:1: PlatformWeb.PlugRouter.plug_builder_call/2
(phoenix 1.5.3) lib/phoenix/router/route.ex:41:
(phoenix 1.5.3) lib/phoenix/router.ex:352:
(platform 0.1.0) lib/plug/error_handler.ex:65:
(platform 0.1.0) lib/platform_web/endpoint.ex:1: PlatformWeb.Endpoint.plug_builder_call/2
(platform 0.1.0) lib/plug/debugger.ex:132: PlatformWeb.Endpoint.“call (overridable 3)”/2
(platform 0.1.0) lib/platform_web/endpoint.ex:1: PlatformWeb.Endpoint.“call (overridable 4)”/2
(platform 0.1.0) lib/platform_web/endpoint.ex:1:
(phoenix 1.5.3) lib/phoenix/endpoint/cowboy2_handler.ex:65: Phoenix.Endpoint.Cowboy2Handler.init/4
(cowboy 2.8.0) /Users/carl/Dev/api/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2
(cowboy 2.8.0) /Users/carl/Dev/api/deps/cowboy/src/cowboy_stream_h.erl:300: :cowboy_stream_h.execute/3
(cowboy 2.8.0) /Users/carl/Dev/api/deps/cowboy/src/cowboy_stream_h.erl:291: :cowboy_stream_h.request_process/3
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

favicon.ico is requested automatically by browsers when you open a window/tab hitting your phoenix app. There’s nothing making your phoenix app return your favicon of your frontend unless you explicitly implement it to do that.

1 Like

Is my thinking incorrect about the error being caused by the favicon? The error isn’t clear to me, so i could be my misreading its the favicon

The error is clear that someone (likely a browser) is requesting /favicon.ico, but your phoenix app is not serving a file for that path, but seems to fail in some controller.

Now the question is: Do you expect your phoenix app to serve a favicon?

If not you’ll need to find out who’s requesting that file and possibly stop it.

If you do, then you need to change your phoenix app in some way, so it knows how to serve your request without hitting your controller in the end.

1 Like

@LostKobrakai IMO it’s fair to expect this to at least not error in dev env. It’s a pretty standard stuff after all. Plus I’ve seen Phoenix generate a favicon.ico file before (although I wouldn’t swear my life on it).

@CarlB maybe something like this in your endpoint.ex file could help:

 plug Plug.Static,
  at: "/",
  from: :YOUR_APP,
  gzip: false,
  only: ~w(css fonts images js favicon.ico robots.txt)

It does by default generate a favicon, but it seems that this has been removed or changed. My point is that it’s not to be expected that phoenix would magically pull the favicon out of the separate frontend app, which doesn’t even seem to be served by phoenix.

1 Like