68 lines
1.7 KiB
Lua
68 lines
1.7 KiB
Lua
---
|
||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||
--- Created by admin.
|
||
--- DateTime: 2025/10/28 11:09
|
||
---
|
||
--解析url路由过滤库
|
||
local radix = require("resty.radixtree")
|
||
--数据表业务处理
|
||
local loginService = require("service.system.login")
|
||
|
||
--定义相关路由,前端接口url地址
|
||
local routes = {
|
||
--------------------------------------------
|
||
-------------用户认证相关路由配置--------------
|
||
--------------------------------------------
|
||
--用户登录路由接口
|
||
{
|
||
paths = { "/yum/v1/system/user/login" },
|
||
methods = { "POST" },
|
||
handler = loginService.login,
|
||
},
|
||
--用户注册路由接口
|
||
{
|
||
paths = { "/yum/v1/system/user/signup" },
|
||
methods = { "POST" },
|
||
handler = loginService.signup,
|
||
},
|
||
--用户退出路由接口
|
||
{
|
||
paths = { "/yum/v1/system/user/logout" },
|
||
methods = { "POST" },
|
||
handler = loginService.logout,
|
||
},
|
||
--根据token信息获取用户信息数据
|
||
{
|
||
paths = { "/yum/v1/system/user/user" },
|
||
methods = { "GET" },
|
||
handler = loginService.user,
|
||
},
|
||
--根据token信息获取用户权限数据
|
||
{
|
||
paths = { "/yum/v1/system/user/permission" },
|
||
methods = { "GET" },
|
||
handler = loginService.permission,
|
||
},
|
||
}
|
||
|
||
-- 初始化路由
|
||
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
|