Simon H Simon H - 1 year ago 116
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

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

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

This controller

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

plug :action

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

And my files in

But when I surf to /elm I get

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

Answer Source

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)