Simon H Simon H - 2 months ago 27
HTML Question

Static HTML page in Phoenix

I'm trying to build a JSON backend for Elm. I only want to serve one page - elm.html, one js file - Main.js - and one css file.

I tried following these instructions but there is not enough there to help a complete newbie like me.

So now I have router.ex

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

get "/elm", RootController, :index
get "/", PageController, :index
end


# Other scopes may use custom stacks.
scope "/api", JwtExample do
pipe_through :api

resources "/users", UserController, except: [:new, :edit]
end


This controller

defmodule JwtExample.RootController do
use JwtExample.Web, :controller

plug :action

def index(conn, _params) do
redirect conn, to: "/elm.html"
end
end


And my files in
web/static
and
priv/static


But when I surf to /elm I get


no route found for GET /elm.html (JwtExample.Router)

Answer

OK, so based on psantos answer, I needed to change lib/endpoint.ex to read

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