AuthPlatform/src/api/api.lua

46 lines
1.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/9/24 15:29
---
local radix = require("resty.radixtree")
local userApi = require("api.system.user")
--定义相关路由前端接口url地址
local routes = {
{
paths = { "/api/user" },
metadata = { "metadata user" },
methods = { "GET", "POST" },
handler = userApi.get_allusers,
},
{
paths = { "/api/user/:id" },
metadata = { "metadata /api/user/id" },
methods = { "GET", "PUT", "DELETE" },
handler = userApi.get_user,
},
}
-- 初始化路由
local rx, err = radix.new(routes)
if not rx then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end
--获取访问的uri地址
local uri = ngx.var.uri
local opts = {
method = ngx.var.request_method,
--vars = ngx.var,
matched = {}
}
-- 进行路由匹配和相关函数调用
local ok = rx:dispatch(uri, opts, opts.matched)
if not ok then
ngx.say("Not Found")
ngx.exit(ngx.HTTP_NOT_FOUND)
end