96 lines
2.5 KiB
Lua
96 lines
2.5 KiB
Lua
---
|
||
--- 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")
|
||
local accountApi = require("api.system.account")
|
||
|
||
--定义相关路由,前端接口url地址
|
||
local routes = {
|
||
--用户相关路由接口
|
||
{
|
||
paths = { "/api/get-user" },
|
||
metadata = { "metadata get-user" },
|
||
methods = { "GET" },
|
||
handler = userApi.get_alluser,
|
||
},
|
||
{
|
||
paths = { "/api/get-user/:id" },
|
||
metadata = { "metadata /api/get-user/id" },
|
||
methods = { "GET" },
|
||
handler = userApi.get_user,
|
||
},
|
||
{
|
||
paths = { "/api/delete-user/:id" },
|
||
metadata = { "metadata /api/delete-user/id" },
|
||
methods = { "DELETE" },
|
||
handler = userApi.delete_user,
|
||
},
|
||
{
|
||
paths = { "/api/add-user" },
|
||
metadata = { "metadata /api/add-user" },
|
||
methods = { "POST" },
|
||
handler = userApi.add_user,
|
||
},
|
||
{
|
||
paths = { "/api/update-user/:id" },
|
||
metadata = { "metadata /api/update-user/id" },
|
||
methods = { "PUT" },
|
||
handler = userApi.update_user,
|
||
},
|
||
--账户相关路由接口
|
||
{
|
||
paths = { "/api/get-accounts" },
|
||
metadata = { "metadata get-accounts" },
|
||
methods = { "GET" },
|
||
handler = accountApi.get_allaccounts,
|
||
},
|
||
{
|
||
paths = { "/api/get-account/:id" },
|
||
metadata = { "metadata /api/get-account/id" },
|
||
methods = { "GET" },
|
||
handler = accountApi.get_account,
|
||
},
|
||
{
|
||
paths = { "/api/delete-account/:id" },
|
||
metadata = { "metadata /api/delete-account/id" },
|
||
methods = { "DELETE" },
|
||
handler = accountApi.delete_account,
|
||
},
|
||
{
|
||
paths = { "/api/add-account" },
|
||
metadata = { "metadata /api/add-account" },
|
||
methods = { "POST" },
|
||
handler = accountApi.add_account,
|
||
},
|
||
{
|
||
paths = { "/api/update-account/:id" },
|
||
metadata = { "metadata /api/update-account/id" },
|
||
methods = { "PUT" },
|
||
handler = accountApi.update_account,
|
||
},
|
||
}
|
||
|
||
-- 初始化路由
|
||
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,
|
||
matched = {}
|
||
}
|
||
|
||
-- 进行路由匹配和相关函数调用
|
||
local ok = rx:dispatch(uri, opts, opts.matched)
|
||
if not ok then
|
||
ngx.say("Not Found")
|
||
ngx.exit(ngx.HTTP_NOT_FOUND)
|
||
end
|