From 59ab5b7b26d9d4b91a6d22b8115eac88a8653caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E7=A4=BC=E6=88=90?= Date: Thu, 23 Feb 2023 18:02:06 +0800 Subject: [PATCH] fix http handler --- apps/iot/src/http_protocol.erl | 5 +++-- apps/iot/src/iot_app.erl | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/iot/src/http_protocol.erl b/apps/iot/src/http_protocol.erl index b592b64..4b1500c 100644 --- a/apps/iot/src/http_protocol.erl +++ b/apps/iot/src/http_protocol.erl @@ -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]), diff --git a/apps/iot/src/iot_app.erl b/apps/iot/src/iot_app.erl index 21fa332..46d6d65 100644 --- a/apps/iot/src/iot_app.erl +++ b/apps/iot/src/iot_app.erl @@ -35,7 +35,7 @@ start_http_server() -> Dispatcher = cowboy_router:compile([ {'_', [ - {"/api/[...]", http_protocol, []} + {"/api/[...]", http_protocol, [http_api_handler]} ]} ]), TransOpts = [