Hagia
log in
morj / pokesz
overview
files
history
wiki
Viewing at
-module(erserver_app).
-behaviour(application).

-export([start/2]).
-export([stop/1]).

start(_Type, _Args) ->
PortStr = os:getenv("PORT", "31337"),
{Port, _} = string:to_integer(PortStr),
DebugModeEnv = os:getenv("DEBUG_MODE", "false"),

ClientManager = spawn(websocket_handler, client_manager, []),
Dispatch = cowboy_router:compile([
{ '_'
, [ {"/", websocket_handler, {ClientManager}}
, {"/", cowboy_static, {priv_file, erlang_server, "client/host.html"}}
, {"/host.js", cowboy_static, {priv_file, erlang_server, "client/host.js"}}
, {"/types.js", cowboy_static, {priv_file, erlang_server, "client/types.js"}}
, {"/watcher.js", cowboy_static, {priv_file, erlang_server, "client/watcher.js"}}
, {"/watch", cowboy_static, {priv_file, erlang_server, "client/watcher.html"}}
]
}
]),
if
DebugModeEnv =:= "true" ->
Opts =
[ {certfile, "../cert.pem"}
, {keyfile, "../key.pem"}
, {port, Port}
, inet
, inet6
],
{ok, _} = cowboy:start_tls(
pokesz_erserver,
Opts,
#{env => #{dispatch => Dispatch}}
);
true ->
Opts =
[ {port, Port}
, inet6
, {ip, {0,0,0,0,0,0,0,1}} %% ::1
],
{ok, _} = cowboy:start_clear(
pokesz_erserver,
Opts,
#{env => #{dispatch => Dispatch}}
)
end,
erserver_sup:start_link().

stop(_State) ->
ok.