diff --git a/apps/iot/src/http/http_server.erl b/apps/iot/src/http/http_server.erl index 0f1c535..f23fc61 100644 --- a/apps/iot/src/http/http_server.erl +++ b/apps/iot/src/http/http_server.erl @@ -89,7 +89,12 @@ parse_body(Req0) -> case ContentType of <<"application/json", _/binary>> -> {ok, Body, Req1} = read_body(Req0), - {ok, catch jiffy:decode(Body, [return_maps]), Req1}; + case Body =/= <<"">> of + true -> + {ok, catch jiffy:decode(Body, [return_maps]), Req1}; + false -> + {ok, #{}, Req1} + end; <<"application/x-www-form-urlencoded">> -> {ok, PostParams0, Req1} = cowboy_req:read_urlencoded_body(Req0), PostParams = maps:from_list(PostParams0), diff --git a/apps/iot/src/mnesia/service_config_model.erl b/apps/iot/src/mnesia/service_config_model.erl index ba46c0b..f37fa2b 100644 --- a/apps/iot/src/mnesia/service_config_model.erl +++ b/apps/iot/src/mnesia/service_config_model.erl @@ -89,7 +89,20 @@ get_config(ServiceId) when is_binary(ServiceId) -> -spec delete(ServiceId :: binary()) -> ok | {error, Reason :: any()}. delete(ServiceId) when is_binary(ServiceId) -> - case mnesia:transaction(fun() -> mnesia:delete(?TAB, ServiceId, write) end) of + Fun = fun() -> + case mnesia:read(?TAB, ServiceId, write) of + [] -> + ok; + [ServiceConfig0 = #service_config{config_json = OldConfigJson}] -> + NServiceConfig = ServiceConfig0#service_config{ + config_json = <<"">>, + last_config_json = OldConfigJson, + update_ts = iot_util:current_time() + }, + mnesia:write(?TAB, NServiceConfig, write) + end + end, + case mnesia:transaction(Fun) of {'atomic', ok} -> ok; {'aborted', Reason} -> diff --git a/config/vm.args b/config/vm.args index d7b21cd..ebb0cf6 100644 --- a/config/vm.args +++ b/config/vm.args @@ -1,4 +1,4 @@ --sname iot +-name iot -setcookie iot_cookie