AuthPlatform/src/api/api.lua

51 lines
1.2 KiB
Lua
Raw Normal View History

2025-09-27 15:14:13 +08:00
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/9/24 15:29
2025-09-27 15:14:13 +08:00
---
local radix = require("resty.radixtree")
local userApi = require("api.system.user")
2025-09-27 15:14:13 +08:00
local routes = {
{
paths = { "/api/user" },
metadata = { "metadata /user" },
methods = { "GET", "POST" },
handler = userApi.get_allusers,
},
{
paths = { "/api/user/:id" },
metadata = { "metadata /user/id" },
methods = { "GET", "PUT", "DELETE" },
handler = userApi.get_users,
},
{
paths = { "/api/admin/:name", "/api/superuser/:name" },
metadata = { "metadata /admin/name" },
methods = { "GET", "POST", "PUT" },
filter_fun = function(vars, opts)
return vars["arg_access"] == "admin"
end
}
2025-09-27 15:14:13 +08:00
}
local rx, err = radix.new(routes)
if not rx then
ngx.say("-----")
ngx.status = 404
ngx.say("Not Found")
--ngx.exit()
2025-09-27 15:14:13 +08:00
end
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
matched = {}
}
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.status = 404
ngx.say("Not Found")
--ngx.exit()
end