2 %% @copyright {{year}} {{author}}
4 %% @doc Web server for {{appid}}.
6 -module({{appid}}_web).
9 -export([start/1, stop/0, loop/2]).
14 {DocRoot, Options1} = get_option(docroot, Options),
16 ?MODULE:loop(Req, DocRoot)
18 mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
21 mochiweb_http:stop(?MODULE).
24 "/" ++ Path = Req:get(path),
26 case Req:get(method) of
27 Method when Method =:= 'GET'; Method =:= 'HEAD' ->
30 Req:serve_file(Path, DocRoot)
38 Req:respond({501, [], []})
42 Report = ["web request failed",
44 {type, Type}, {what, What},
45 {trace, erlang:get_stacktrace()}],
46 error_logger:error_report(Report),
47 %% NOTE: mustache templates need \\ because they are not awesome.
48 Req:respond({500, [{"Content-Type", "text/plain"}],
49 "request failed, sorry\\n"})
54 get_option(Option, Options) ->
55 {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
61 -include_lib("eunit/include/eunit.hrl").
63 you_should_write_a_test() ->
66 "Have you written any tests?"),