I’ve been attempting to serve a simple index.html
file using cowboy (and failing).
After 12 hours of searching around, and seeing many examples online of similar content being served by cowboy, I’ve come up empty on my own personal project.
I have been successful in serving json and html within the handler, just not a static html file served from /priv
in my project directory unfortunately.
Please let me know if there’s anything wrong with what I currently have (routes, listener, and handler) or if you have any suggestions.
Thank you.
self_app.erl
% self_app.erl
start(_Type, _Args) ->
Dispatch = cowboy_router:compile([
{'_', [
{"/", cowboy_static,
{priv_file, self_handler,"index.html",
[{mimetypes, {<<"text">>, <<"html">>, []}}]}
}
]}
]),
{ok, _} = cowboy:start_clear(self_http_server, [{port, 8080}], #{env =>
#{dispatch => Dispatch}}),
self_sup:start_link().
self_handler.erl
% self_handler.erl
init(Req0, State) ->
Req = cowboy_req:reply(200,
#{<<"content-type">> => <<"text/html">>}, Req0
),
{ok, Req, State}.
System Info
Distro: Linux Mint 20.3 Una base: Ubuntu 20.04 focal
------------
Erlang/OTP 25 [erts-13.0] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]
------------
Cowboy 2.9.0