Compare commits
2 Commits
94ebf0a452
...
7529cb9114
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7529cb9114 | ||
|
|
174e4aadb9 |
|
|
@ -7,10 +7,9 @@ events {
|
||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
lua_package_path '$profix/src/?/?.lua;$profix/src/?.lua;;';
|
lua_package_path '$prefix/src/?/?.lua;$prefix/src/?.lua;/home/frankly/work/AuthPlatform/src/?.lua;/home/frankly/work/AuthPlatform/src/?/?.lua;;';
|
||||||
lua_package_cpath '$profix/src/share/lib/?.so;;';
|
lua_package_cpath '$prefix/src/share/lib/?.so;;';
|
||||||
|
|
||||||
include system/user.conf
|
|
||||||
# Path of the file with trusted CA certificates.
|
# Path of the file with trusted CA certificates.
|
||||||
#lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
|
#lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
|
||||||
|
|
||||||
|
|
@ -25,5 +24,7 @@ http {
|
||||||
log_not_found off;
|
log_not_found off;
|
||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include 'system/user.conf';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,51 +4,23 @@
|
||||||
--- DateTime: 2025/9/24 15:29
|
--- DateTime: 2025/9/24 15:29
|
||||||
---
|
---
|
||||||
local radix = require("resty.radixtree")
|
local radix = require("resty.radixtree")
|
||||||
|
local userApi = require("api.system.user")
|
||||||
local function say_hello(req)
|
|
||||||
ngx.say("Hello, World!")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_user(req)
|
|
||||||
local user_id = req.args.id or "unknown"
|
|
||||||
ngx.say("User ID: " .. user_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_id(req)
|
|
||||||
local args = req.get_uri_args()
|
|
||||||
-- 获取单个参数
|
|
||||||
local id = args["id"] -- 值为 "john"
|
|
||||||
ngx.say("User ID: " .. user_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function test(req)
|
|
||||||
local request_method = ngx.var.request_method
|
|
||||||
local args = nil
|
|
||||||
ngx.say(request_method)
|
|
||||||
|
|
||||||
--1、获取参数的值 获取前端提交参数
|
|
||||||
if "GET" == request_method then
|
|
||||||
args = ngx.req.get_uri_args()
|
|
||||||
elseif "POST" == request_method then
|
|
||||||
ngx.req.read_body()
|
|
||||||
args = ngx.req.get_post_args()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local routes = {
|
local routes = {
|
||||||
{
|
{
|
||||||
paths = { "/login/*action" },
|
paths = { "/api/user" },
|
||||||
metadata = { "metadata /login/action" },
|
metadata = { "metadata /user" },
|
||||||
methods = { "GET", "POST", "PUT" },
|
methods = { "GET", "POST" },
|
||||||
remote_addrs = { "127.0.0.1", "192.168.0.0/16", "::1", "fe80::/32" }
|
handler = userApi.get_allusers,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
paths = { "/user/:name" },
|
paths = { "/api/user/:id" },
|
||||||
metadata = { "metadata /user/name" },
|
metadata = { "metadata /user/id" },
|
||||||
methods = { "GET" },
|
methods = { "GET", "PUT", "DELETE" },
|
||||||
|
handler = userApi.get_users,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
paths = { "/admin/:name", "/superuser/:name" },
|
paths = { "/api/admin/:name", "/api/superuser/:name" },
|
||||||
metadata = { "metadata /admin/name" },
|
metadata = { "metadata /admin/name" },
|
||||||
methods = { "GET", "POST", "PUT" },
|
methods = { "GET", "POST", "PUT" },
|
||||||
filter_fun = function(vars, opts)
|
filter_fun = function(vars, opts)
|
||||||
|
|
@ -57,23 +29,23 @@ local routes = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local function handle_request()
|
local rx, err = radix.new(routes)
|
||||||
--获取接口请求的方法
|
if not rx then
|
||||||
local request_method = ngx.var.request_method
|
ngx.say("-----")
|
||||||
ngx.say(request_method)
|
ngx.status = 404
|
||||||
|
ngx.say("Not Found")
|
||||||
local args = ngx.var.get_uri_args
|
--ngx.exit()
|
||||||
ngx.say(request_method)
|
|
||||||
|
|
||||||
local uri = ngx.var.request_uri
|
|
||||||
ngx.say("url: " .. uri)
|
|
||||||
local handler = routes[uri]
|
|
||||||
if handler then
|
|
||||||
handler(ngx.req)
|
|
||||||
else
|
|
||||||
ngx.status = 404
|
|
||||||
ngx.say("Not Found")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
handle_request()
|
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
|
||||||
|
|
@ -4,17 +4,16 @@
|
||||||
--- DateTime: 2025/9/25 08:19
|
--- DateTime: 2025/9/25 08:19
|
||||||
---
|
---
|
||||||
|
|
||||||
local db_config = require('config.database')
|
local _M = {}
|
||||||
local pgmoon = require('share.pgmoonn')
|
|
||||||
|
|
||||||
-- 创建一个新的连接
|
--获取所有用户信息
|
||||||
local conn = pgmoon.new(db_config.postgres)
|
function _M.get_allusers()
|
||||||
|
|
||||||
-- 连接到数据库
|
end
|
||||||
conn:connect(function(err)
|
|
||||||
if err then
|
--获取所有用户信息
|
||||||
print("Error connecting to database: ", err)
|
function _M.get_users(req)
|
||||||
else
|
|
||||||
print("Connected to the PostgreSQL server.")
|
end
|
||||||
end
|
|
||||||
end)
|
return _M
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
---
|
---
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||||
--- Created by admin.
|
--- Created by .
|
||||||
--- DateTime: 2025/9/25 08:19
|
--- DateTime: 2025/9/25 08:19
|
||||||
--- 业务逻辑
|
--- 业务逻辑
|
||||||
local db_config = require('config.database')
|
local cjson = require('cjson')
|
||||||
local pgmoon = require('share.pgmoonn')
|
local pgmoon = require('pgmoon');
|
||||||
|
|
||||||
|
local _M = {}
|
||||||
|
|
||||||
-- 创建一个新的连接
|
-- 创建一个新的连接
|
||||||
local conn = pgmoon.new(db_config.postgres)
|
local conn = pgmoon.new(db_config.postgres)
|
||||||
|
|
@ -17,3 +19,9 @@ conn:connect(function(err)
|
||||||
print("Connected to the PostgreSQL server.")
|
print("Connected to the PostgreSQL server.")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
function _M.getAllUser()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return _M
|
||||||
|
|
@ -27,7 +27,7 @@ local API = require("LuaORM.API")
|
||||||
|
|
||||||
-- 2. Configure the ORM
|
-- 2. Configure the ORM
|
||||||
API.ORM:initialize({
|
API.ORM:initialize({
|
||||||
connection = "LuaSQL/postgres",
|
connection = "LuaSQL/PostgreSQL",
|
||||||
database = {
|
database = {
|
||||||
databaseName = "postgres",
|
databaseName = "postgres",
|
||||||
userName = "postgres",
|
userName = "postgres",
|
||||||
|
|
@ -397,41 +397,3 @@ end
|
||||||
|
|
||||||
local timePassed = os.clock() - startTimeStamp
|
local timePassed = os.clock() - startTimeStamp
|
||||||
print("\nExecution took " .. timePassed .. " seconds")
|
print("\nExecution took " .. timePassed .. " seconds")
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
----------------------------- REQUIRE --------------------------------
|
|
||||||
local Table = require("orm.model")
|
|
||||||
local fields = require("orm.tools.fields")
|
|
||||||
|
|
||||||
----------------------------- CREATE TABLE --------------------------------
|
|
||||||
|
|
||||||
local User = Table({
|
|
||||||
__tablename__ = "user",
|
|
||||||
username = fields.CharField({max_length = 100, unique = true}),
|
|
||||||
password = fields.CharField({max_length = 50, unique = true}),
|
|
||||||
age = fields.IntegerField({max_length = 2, null = true}),
|
|
||||||
job = fields.CharField({max_length = 50, null = true}),
|
|
||||||
time_create = fields.DateTimeField({null = true})
|
|
||||||
})
|
|
||||||
|
|
||||||
----------------------------- CREATE DATA --------------------------------
|
|
||||||
local user = User({
|
|
||||||
id = 1,
|
|
||||||
username = "zhangsan",
|
|
||||||
password = "123456",
|
|
||||||
time_create = os.time()
|
|
||||||
})
|
|
||||||
|
|
||||||
--user:save()
|
|
||||||
ngx.say("User " .. user.username .. " has id " .. user.id)
|
|
||||||
-- User Bob Smith has id 1
|
|
||||||
|
|
||||||
----------------------------- GET DATA --------------------------------
|
|
||||||
local first_user = User.get:first()
|
|
||||||
ngx.print("First user name is: " .. first_user.username)
|
|
||||||
-- First user name is: First user
|
|
||||||
|
|
||||||
local users = User.get:all()
|
|
||||||
ngx.print("We get " .. users:count() .. " users")
|
|
||||||
-- We get 5 users
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user