You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/27 08:34:19 UTC
[GitHub] [apisix] backnero opened a new issue #2872: I want to return routing data through the interface
backnero opened a new issue #2872:
URL: https://github.com/apache/apisix/issues/2872
I want to return routing data through the interface. This is the source code of my plug-in, but now the return value is empty. How can I implement it?
```
local core = require("apisix.core")
local ipairs = ipairs
local ngx = ngx
local ngx_time = ngx.time
local sub_str = string.sub
local plugin_name = "dev"
local http = require("resty.http")
local json = require("apisix.core.json")
local type = type
local string = string
-- local router = require("apisix.router")
-- local get_routes = router.http_routes
-- local profile = require("apisix.core.profile")
-- local lfs = require("lfs")
-- local re_find = ngx.re.find
local yaml = require("tinyyaml")
-- local apisix_yaml_path = profile:yaml_path("apisix")
local loadstring = loadstring
local user_routes
local router = require("resty.radixtree")
local schema = {
type = "object",
properties = {
},
}
local _M = {
version = 0.1,
priority = 70000,
type = 'auth',
name = plugin_name,
schema = schema,
}
function _M.check_schema(conf)
core.log.info("input conf: ", core.json.delay_encode(conf))
local ok, err = core.schema.check(schema, conf)
if not ok then
return false, err
end
return true
end
local function fail_response(message, init_values)
local response = init_values or {}
response.message = message
return response
end
local function success_response(message, init_values)
local response = init_values or {}
response.message = message
return response
end
local function create_radixtree_router(routes)
local uri_routes = {}
local uri_router
routes = routes or {}
core.table.clear(uri_routes)
for _, route in ipairs(routes) do
core.log.error("route for: ", core.json.delay_encode(route, true))
if type(route) == "table" then
local filter_fun, err
if route.value.filter_func then
filter_fun, err = loadstring(
"return " .. route.value.filter_func,
"router#" .. route.value.id)
if not filter_fun then
core.log.error("failed to load filter function: ", err,
" route id: ", route.value.id)
goto CONTINUE
end
filter_fun = filter_fun()
end
core.log.error("insert uri route: ",
core.json.delay_encode(route.value))
core.table.insert(uri_routes, {
paths = route.value.uris or route.value.uri,
methods = route.value.methods,
priority = route.value.priority,
hosts = route.value.hosts or route.value.host,
remote_addrs = route.value.remote_addrs
or route.value.remote_addr,
vars = route.value.vars,
filter_fun = filter_fun,
handler = function (api_ctx, match_opts)
api_ctx.matched_params = nil
api_ctx.matched_route = route
api_ctx.curr_req_matched = match_opts.matched
end
})
::CONTINUE::
end
end
-- core.log.error("route items:2 ",core.json.uri_routes)
uri_router = router.new(uri_routes)
core.response.exit(200, success_response(nil, {routes = uri_routes}))
end
function get_routes()
local user_routes, err = core.config.new("/routes", {
automatic = true,
item_schema = core.schema.route,
filter = filter,
})
create_radixtree_router(user_routes.values)
-- core.log.error("route items:1 ", core.json.uri_routes)
end
function _M.api()
return {
{
methods = {"GET"},
uri = "/apisix/plugin/routes",
handler = get_routes,
}
}
end
return _M
```
response
```
{
"routes": {}
}
```
_Originally posted by @backnero in https://github.com/apache/apisix/issues/2855#issuecomment-734712258_
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] membphis commented on issue #2872: I want to return routing data through the interface
Posted by GitBox <gi...@apache.org>.
membphis commented on issue #2872:
URL: https://github.com/apache/apisix/issues/2872#issuecomment-734732261
You can submitted in PR the we can discuss it.
By the way, if you can write some use case in PR, that would be great.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] github-actions[bot] closed issue #2872: I want to return routing data through the interface
Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #2872:
URL: https://github.com/apache/apisix/issues/2872
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] github-actions[bot] commented on issue #2872: I want to return routing data through the interface
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #2872:
URL: https://github.com/apache/apisix/issues/2872#issuecomment-979845059
This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] github-actions[bot] commented on issue #2872: I want to return routing data through the interface
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #2872:
URL: https://github.com/apache/apisix/issues/2872#issuecomment-966976444
This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org