fix http handler
This commit is contained in:
parent
905ddbcecd
commit
59ab5b7b26
@ -12,8 +12,9 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([init/2]).
|
-export([init/2]).
|
||||||
|
|
||||||
init(Req0, Opts) ->
|
init(Req0, Opts = [Mod|_]) ->
|
||||||
StartTs = erlang:monotonic_time(),
|
StartTs = erlang:monotonic_time(),
|
||||||
|
lager:debug("opts is: ~p", [Opts]),
|
||||||
|
|
||||||
Method = binary_to_list(cowboy_req:method(Req0)),
|
Method = binary_to_list(cowboy_req:method(Req0)),
|
||||||
Path = binary_to_list(cowboy_req:path(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),
|
{ok, PostParams0, Req1} = cowboy_req:read_urlencoded_body(Req0),
|
||||||
PostParams = maps:from_list(PostParams0),
|
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} ->
|
{ok, StatusCode, Resp} ->
|
||||||
lager:debug("[http_protocol] get a request, path: ~p, get params: ~p, post params: ~p, response: ~ts",
|
lager:debug("[http_protocol] get a request, path: ~p, get params: ~p, post params: ~p, response: ~ts",
|
||||||
[Path, GetParams, PostParams, Resp]),
|
[Path, GetParams, PostParams, Resp]),
|
||||||
|
|||||||
@ -35,7 +35,7 @@ start_http_server() ->
|
|||||||
|
|
||||||
Dispatcher = cowboy_router:compile([
|
Dispatcher = cowboy_router:compile([
|
||||||
{'_', [
|
{'_', [
|
||||||
{"/api/[...]", http_protocol, []}
|
{"/api/[...]", http_protocol, [http_api_handler]}
|
||||||
]}
|
]}
|
||||||
]),
|
]),
|
||||||
TransOpts = [
|
TransOpts = [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user