mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-03 04:27:36 +08:00
feature: supported to run the mini case.
``` curl http://test.com:9080/hello run route id: 1234 host: test.com ```
This commit is contained in:
parent
e083f9be46
commit
25b2bc84cd
@ -4,6 +4,7 @@ local log = require("apimeta.comm.log")
|
||||
local resp = require("apimeta.comm.resp")
|
||||
local route_handler = require("apimeta.route.handler")
|
||||
local ngx_req = ngx.req
|
||||
local ngx_var = ngx.var
|
||||
|
||||
local _M = {}
|
||||
|
||||
@ -25,7 +26,8 @@ function _M.access()
|
||||
end
|
||||
|
||||
api_ctx.method = api_ctx.method or ngx_req.get_method()
|
||||
api_ctx.uri = api_ctx.uri or ngx.var.uri
|
||||
api_ctx.uri = api_ctx.uri or ngx_var.uri
|
||||
api_ctx.host = api_ctx.host or ngx_var.host
|
||||
|
||||
local router = route_handler.get_router()
|
||||
local ok = router:dispatch(api_ctx.method, api_ctx.uri, api_ctx)
|
||||
|
@ -13,19 +13,28 @@ local _M = {}
|
||||
function _M.get_router()
|
||||
if router == nil then
|
||||
log.warn("generate a empty router instance")
|
||||
return _M.load({ {methods = {"GET"}, uri = "/hello", router_id = "xx"} })
|
||||
|
||||
-- todo: only for test now
|
||||
return _M.load_route({
|
||||
{
|
||||
methods = {"GET"},
|
||||
uri = "/hello",
|
||||
host = "test.com",
|
||||
id = 1234,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return router
|
||||
end
|
||||
|
||||
|
||||
local function run_route(params, route, ...)
|
||||
ngx.say("run route")
|
||||
local function run_route(params, route, api_ctx)
|
||||
ngx.say("run route id: ", route.id, " host: ", api_ctx.host)
|
||||
end
|
||||
|
||||
|
||||
function _M.load(routes)
|
||||
function _M.load_route(routes)
|
||||
if router then
|
||||
router:tree_free()
|
||||
router = nil
|
||||
@ -37,7 +46,7 @@ function _M.load(routes)
|
||||
route.methods,
|
||||
route.uri,
|
||||
function (params, ...)
|
||||
return run_route(params, router, ...)
|
||||
return run_route(params, route, ...)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user