NEVER PUT YOUR ROUTES DIRECTLY WITHIN THE PIPELINE ALWAYS PUT IT THROUGH THE SCOPE (Example below). WHEN YOU PUT IT THROUGH THE PIPELINE, IT WILL NOT WORK. I’VE MADE THIS MISTAKE BEFORE, BUT I’M APARENTLY THE ONLY ONE DUMB ENOUGH TO MAKE THE MISTAKE NOT ONLY ONCE, BUT TWICE, SO NOW I’VE DOCUMENTED IT FOR ALLL THAT MAY FIND AND BENEFIT FROM THIS HORRIFICally AWESOME POST In my case I would hit the endpoint /api/searches/ BECAUSE I PUT IT THROUGH THE API SCOPE WHICH PREPENDS THE /api to the url.

defmodule DecideTheNight.Router do
  use DecideTheNight.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]

    resources "/searches", SearchController, except: [:new, :edit] # BAD BAD BAD BAD BAD BAD DONT BUT THAT SHIT HEREERERERERERE
  end

  scope "/", DecideTheNight do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
  end

  # Other scopes may use custom stacks.
  scope "/api", DecideTheNight do
    pipe_through :api
    resources "/searches", SearchController, except: [:new, :edit] # YERRRSSSS PUT IT HERE PUT IT INNNNNN
  end
end

Post Content