Cowboy only routes the first pattern

I’m compiling my routes as such

    Dispatch = cowboy_router:compile([
				      {'_', [{"/", debug_handler, []}]},
				      {'_', [{"/sysinfo", sysinfo_handler, []}]},
				      {'_', [{"/proc", proc_handler, []}]}
				     ]),

    {ok, _} = cowboy:start_clear(http_listener,
				 [{port, 8080}],
				 #{env => #{dispatch => Dispatch}}
				).

Whatever the first element is in the list is the only thing that I can visit, everything else gives a 404. I’ve tried every permutation of the three routes, and it’s only the first in the list.

Where am I going wrong?

TIA

You are close but try this instead.

Dispatch = cowboy_router:compile([
			      {'_', [{"/", debug_handler, []},
                         {"/sysinfo", sysinfo_handler, []},
                         {"/proc", proc_handler, []}]}]),

{ok, _} = cowboy:start_clear(http_listener,
			 [{port, 8080}],
			 #{env => #{dispatch => Dispatch}}
			).

The first pattern match is on the Hostname. In my experience of using cowboy you only want the default match for that. My solution matches the default hostname, and then tries to match the path as you would expect.

That was it, thank you so much

1 Like