init() ->
Ip = "0.0.0.0" ,
Port = 8000 ,
Options = [ {ip, Ip } ,{port, Port}, {docroot, local_path(["priv", "www"])}
],
{DocRoot, Options1} = get_option(docroot, Options),
Loop = fun (Req) ->
?MODULE:loop(Req, DocRoot)
end,
mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]) .
loop(Req, DocRoot) ->
"/" ++ Path = Req:get(path),
case Req:get(method) of
Method when Method =:= 'GET'; Method =:= 'HEAD' ->
case Path of
"cleanup" -> Req:cleanup(), Req:ok({"application/json", [] , [ jsonx:encode([{status,true}] ) ] });
_ -> Req:serve_file(Path, DocRoot)
end;
_ ->
Req:respond({501, [], []})
end.
Any suggestions .. Thank you .
Golan