have a server that like does stuff now
This commit is contained in:
+34
-3
@@ -263,11 +263,42 @@ default_css(Sock) ->
|
||||
http_err(Sock, 500)
|
||||
end.
|
||||
|
||||
wfcin(Sock, #request{enctype = json, body = #{"wfcin" := Input}}) ->
|
||||
tell("wfcin good request: ~tp", [Input]),
|
||||
RespObj =
|
||||
try
|
||||
case wfc_read:expr(Input) of
|
||||
%% FIXME support multiple expressions
|
||||
{ok, Expr, _Rest} ->
|
||||
case wfc_eval:eval(Expr, wfc_eval_context:default()) of
|
||||
{ok, noop, _NewContext} -> jsgud("<noop>");
|
||||
{ok, Sentence, _NewContext} -> jsgud(wfc_pp:sentence(Sentence));
|
||||
{error, Message} -> jsbad(Message)
|
||||
end;
|
||||
{error, Message} ->
|
||||
jsbad(Message)
|
||||
end
|
||||
catch
|
||||
error:E:S ->
|
||||
ErrorMessage = unicode:characters_to_list(io_lib:format("parser crashed: ~p:~p", [E, S])),
|
||||
jsbad(ErrorMessage)
|
||||
end,
|
||||
Body = zj:encode(RespObj),
|
||||
Response = #response{headers = [{"content-type", "application/json"}],
|
||||
body = Body},
|
||||
respond(Sock, Response);
|
||||
wfcin(Sock, Request) ->
|
||||
tell("wfcin request: ~tp", [Request]),
|
||||
http_err(Sock, 501).
|
||||
tell("wfcin: bad request: ~tp", [Request]),
|
||||
http_err(Sock, 400).
|
||||
|
||||
jsgud(X) ->
|
||||
#{"ok" => true,
|
||||
"result" => X}.
|
||||
|
||||
jsbad(X) ->
|
||||
#{"ok" => false,
|
||||
"error" => X}.
|
||||
|
||||
%% FIXME
|
||||
http_err(Sock, N) ->
|
||||
Slogan = qhl:slogan(N),
|
||||
Body = ["<!doctype html>"
|
||||
|
||||
Reference in New Issue
Block a user