I’m currently trying to build a catch all for the backend.
CONTEXT:
Why? I’m building an SPA application which has run into a router issue. I tried fixing this through webpack, but won’t be a solution for production which lead to modifying the backend.
How? (Implementation) When I first created the project. I opted to not include any html files, controllers etc since I was expecting to use Absinthe/GraphQL to handle all my queries. Currently I have two folds, BACKEND and FRONTEND. The frontend is where my HTML file lives and where we should be finding/hitting for the catch all route.
What? What I’ve done so far for this catch all is as follows:
Implemented a new router to handle a catch all
pipeline :browser do
plug(:accepts, ["html"])
end
scope "/", HuntersWeb do
pipe_through(:browser)
get("/*path", PageController, :index)
end
Next create a controller (which never gets hit since my IO.inspect never runs)
defmodule HuntersWeb.PageController do
use HuntersWeb, :controller
def index(conn, _params) do
render(conn, "index.html") <- Problem since I don't know how to get the right html file
end
end
defmodule HuntersWeb.PageView do
use HuntersWeb, :view
end
All advice is appreciated.
My two main questions are:
1 - How can I use the right html file to render or to point to should a route (refresh) were to be hit.
2 - Did I do something wrong, that is causing the controller not to be hit? (it feels like it isn;t)
Also seeing Cannot GET /store/2
Thanks again for all the help and advice for this one.