From e9cea4407e0308733eae6feb337eba60f249abff Mon Sep 17 00:00:00 2001 From: The-White-Lion <37370573+The-White-Lion@users.noreply.github.com> Date: Wed, 29 Dec 2021 10:15:45 +0800 Subject: [PATCH] feat: support to use path parameter with plugin's control api (#5934) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 罗泽轩 --- apisix/control/router.lua | 15 ++++++++++++++- docs/en/latest/control-api.md | 3 +++ docs/zh/latest/control-api.md | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/apisix/control/router.lua b/apisix/control/router.lua index 43fb7e213989..851dbc872f3b 100644 --- a/apisix/control/router.lua +++ b/apisix/control/router.lua @@ -16,6 +16,7 @@ -- local require = require local router = require("apisix.utils.router") +local radixtree = require("resty.radixtree") local builtin_v1_routes = require("apisix.control.v1") local plugin_mod = require("apisix.plugin") local core = require("apisix.core") @@ -154,7 +155,19 @@ function fetch_control_api_router() handler = empty_func, }) - return router.new(routes) + local with_parameter = false + local conf = core.config.local_conf() + if conf.apisix.enable_control and conf.apisix.control then + if conf.apisix.control.router == "radixtree_uri_with_parameter" then + with_parameter = true + end + end + + if with_parameter then + return radixtree.new(routes) + else + return router.new(routes) + end end end -- do diff --git a/docs/en/latest/control-api.md b/docs/en/latest/control-api.md index 86f5e72fbdfb..a2258d64a06c 100644 --- a/docs/en/latest/control-api.md +++ b/docs/en/latest/control-api.md @@ -38,6 +38,9 @@ apisix: port: 9090 ``` +The control API server does not support parameter matching by default, if you want to enable parameter matching in plugin's control API +you can add `router: 'radixtree_uri_with_parameter'` to the `control` section. + Note that the control API server should not be configured to listen to the public traffic! ## Control API Added via plugin diff --git a/docs/zh/latest/control-api.md b/docs/zh/latest/control-api.md index 5791b11e0e3a..bbebf7658b22 100644 --- a/docs/zh/latest/control-api.md +++ b/docs/zh/latest/control-api.md @@ -37,6 +37,8 @@ apisix: port: 9090 ``` +插件的 control API 在默认情况下不支持参数匹配,如果想启用参数匹配功能可以在 control 部分添加 `router: 'radixtree_uri_with_parameter'` + 注意: control API server 不应该被配置成监听公网地址。 ## 通过插件添加的 control API