fix http handler

This commit is contained in:
安礼成 2023-02-23 18:02:06 +08:00
parent 905ddbcecd
commit 59ab5b7b26
2 changed files with 4 additions and 3 deletions

View File

@ -12,8 +12,9 @@
%% API
-export([init/2]).
init(Req0, Opts) ->
init(Req0, Opts = [Mod|_]) ->
StartTs = erlang:monotonic_time(),
lager:debug("opts is: ~p", [Opts]),
Method = binary_to_list(cowboy_req:method(Req0)),
Path = binary_to_list(cowboy_req:path(Req0)),
@ -22,7 +23,7 @@ init(Req0, Opts) ->
{ok, PostParams0, Req1} = cowboy_req:read_urlencoded_body(Req0),
PostParams = maps:from_list(PostParams0),
try http_api_handler:handle_request(Method, Path, GetParams, PostParams) of
try Mod:handle_request(Method, Path, GetParams, PostParams) of
{ok, StatusCode, Resp} ->
lager:debug("[http_protocol] get a request, path: ~p, get params: ~p, post params: ~p, response: ~ts",
[Path, GetParams, PostParams, Resp]),

View File

@ -35,7 +35,7 @@ start_http_server() ->
Dispatcher = cowboy_router:compile([
{'_', [
{"/api/[...]", http_protocol, []}
{"/api/[...]", http_protocol, [http_api_handler]}
]}
]),
TransOpts = [