I am trying to figure out how to configure Plug.Static without any other framework (Phoenix, Sugar, etc); just Cowboy, Plug and Elixir. I just don't know how to put things together in the Router.
plug :match
plug Plug.Static, at: "/pub", from: :cerber
plug :dispatch
get "/" do
Logger.info "GET /"
send_resp(conn, 200, "Hello world\n")
end
Plug.Static
at the right place ? Shouldn't it be after plug :dispatch
?index.html
?index.html
should be locatedI'm just lost.
Take a look at Plug.Router docs for how :match
and :dispatch
works. :match
will try to find a matching route and :dispatch
is going to invoke it. This means Plug.Static
in your setup will only be invoked if you have a matching route in your router, which doesn't make sense. You want plug Plug.Static
before everything. Remember plugs are just functions that are invoked in the order they are declared.
Other than that, your Plug.Static setup seems ok. Your current configuration will serve assets at "/pub", meaning "/pub/index.html" will look for "priv/static/index.html" in your app. More info here: http://hexdocs.pm/plug/Plug.Static.html