diff --git a/apps/emqx_dashboard/src/emqx_dashboard.erl b/apps/emqx_dashboard/src/emqx_dashboard.erl index ca995990d..a69a1fea2 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard.erl @@ -72,8 +72,7 @@ start_listeners(Listeners) -> {"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}}, {"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}}, {emqx_mgmt_api_status:path(), emqx_mgmt_api_status, []}, - {emqx_dashboard_swagger:relative_uri("/[...]"), emqx_dashboard_bad_api, []}, - {'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}} + {'_', emqx_dashboard_not_found, []} ], BaseMinirest = #{ base_path => emqx_dashboard_swagger:base_path(), diff --git a/apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl b/apps/emqx_dashboard/src/emqx_dashboard_not_found.erl similarity index 63% rename from apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl rename to apps/emqx_dashboard/src/emqx_dashboard_not_found.erl index 6d65ac081..20fe81483 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_bad_api.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_not_found.erl @@ -14,7 +14,7 @@ %% limitations under the License. %%-------------------------------------------------------------------- --module(emqx_dashboard_bad_api). +-module(emqx_dashboard_not_found). -include_lib("emqx/include/logger.hrl"). @@ -23,10 +23,22 @@ init(Req0, State) -> RedactedReq = emqx_utils:redact(Req0), ?SLOG(warning, #{msg => "unexpected_api_access", request => RedactedReq}), + CT = ct(cowboy_req:header(<<"accept">>, Req0, <<"text/html">>)), Req = cowboy_req:reply( 404, - #{<<"content-type">> => <<"application/json">>}, - <<"{\"code\": \"API_NOT_EXIST\", \"message\": \"Request Path Not Found\"}">>, + #{<<"content-type">> => CT}, + ct_body(CT), RedactedReq ), {ok, Req, State}. + +ct(<<"text/plain", _/binary>>) -> <<"text/plain">>; +ct(<<"application/json", _/binary>>) -> <<"application/json">>; +ct(_AnyOther) -> <<"text/html">>. + +ct_body(<<"text/html">>) -> + <<"