diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..c8913d2 --- /dev/null +++ b/build.xml @@ -0,0 +1,41 @@ + + + + + run pic-server + + + + + + + + + ######开发版的ant配置##### + + 清理openresty目录${dist}下的conf,logs,janus,januslib + + + + + + + + + 创建安装目录 + + + + + + 复制安装目录 + + + + + + + + + \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index 114a1d3..dbe25f2 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,29 +1,27 @@ worker_processes 1; -worker_rlimit_nofile 65535; +#worker_rlimit_nofile 65535; events { worker_connections 1024; } http { - include mime.types; - default_type application/octet-stream; - sendfile on; - keepalive_timeout 65; - limit_req_zone $binary_remote_addr zone=one:50m rate=20r/s; - - lua_package_path 'D:/ZeroBraneStudio-1.90/lualibs/?/?.lua;D:/ZeroBraneStudio-1.90/lualibs/?.lua;;'; - lua_package_cpath 'D:/ZeroBraneStudio-1.90/bin/clibs/?.dll;;'; + lua_package_path 'src/?/?.lua;src/?.lua;src/share/?/?.lua;src/share/?.lua;;'; + lua_package_cpath 'src/share/lib/?.so;;'; server { listen 9080; - server_name localhost; + server_name 127.0.0.1; default_type text/html; - - location /test { - default_type 'text/plain'; - content_by_lua_file 'src/test.lua'; + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location /api { + content_by_lua_file '/home/frankly/work/AuthPlatform/src/test.lua'; + #content_by_lua_file 'src/api/api.lua'; } } } \ No newline at end of file diff --git a/src/api/api.lua b/src/api/api.lua index a9f7089..4727234 100644 --- a/src/api/api.lua +++ b/src/api/api.lua @@ -4,10 +4,6 @@ --- DateTime: 2025/9/24 15:29 --- --- local user = require('api.system.user')--- 启动调试 --- local mobdebug = require('src.share.initial.mobdebug'); --- mobdebug.start(); - local function say_hello(req) ngx.say("Hello, World!") end @@ -38,56 +34,8 @@ local function test(req) ngx.req.read_body() args = ngx.req.get_post_args() end - - --2、组合url请求Get/Post请求 并获取参数 - local http = require "resty.http" - local httpc = http.new() - local url = "http://xxxxx/user/login/"..args["userid"].."/"..args["pass"] - local resStr --响应结果 - local res, err = httpc:request_uri(url, { - method = "GET", - --args = str, - body = "a=1&b=2", - headers = { - ["Content-Type"] = "application/json", - } - }) - - --3、开始重新组合参数 例子 可根据返回的JSON自己处理 - local cjson = require "cjson" - local sampleJson = [[{"age":"23","testArray":{"array":[8,9,11,14,25]},"Himi":"himigame.com"}]]; - --解析json字符串 - local data = cjson.decode(sampleJson); - --打印json字符串中的age字段 - ngx.say(data["age"]); - --打印数组中的第一个值(lua默认是从0开始计数) - ngx.say(data["testArray"]["array"][1]); - - --4、打印输出新返回值 - ngx.say(res.body) - - --获取url中a的值 - ngx.say(ngx.var.arg_a); - --获取主机名 - ngx.say(ngx.var.remote_addr); - --获取get和post参数 - local arg = ngx.req.get_uri_args() - for k,v in pairs(arg) do - ngx.say("[GET ] key:", k, " v:", v) - end - - ngx.req.read_body() -- 解析 body 参数之前一定要先读取 body - local arg = ngx.req.get_post_args() - for k,v in pairs(arg) do - ngx.say("[POST] key:", k, " v:", v) - end end ----local function conn() ---- local conn1 = user.conn ---- conn1:connect(...) ----end - local routes = { ["/hello"] = say_hello, ["/user"] = get_user, diff --git a/src/share/pgmoon/init.lua b/src/share/pgmoon/init.lua index 89ac0e2..e42d642 100644 --- a/src/share/pgmoon/init.lua +++ b/src/share/pgmoon/init.lua @@ -116,7 +116,6 @@ local PG_TYPES = { [1016] = "array_number", [1021] = "array_number", [1022] = "array_number", - [1041] = "array_inet", [1231] = "array_number", [1009] = "array_string", [1015] = "array_string", @@ -178,11 +177,6 @@ do bytea = function(self, val, name) return self:decode_bytea(val) end, - array_inet = function(self, val, name) - local decode_array - decode_array = require("pgmoon.arrays").decode_array - return decode_array(val, nil, self) - end, array_boolean = function(self, val, name) local decode_array decode_array = require("pgmoon.arrays").decode_array @@ -347,7 +341,7 @@ do end end, cleartext_auth = function(self, msg) - assert(self.config.password, "the database is requesting a password for authentication but you did not provide a password") + assert(self.config.password, "missing password, required for connect") self:send_message(MSG_TYPE_F.password, { self.config.password, NULL @@ -355,7 +349,7 @@ do return self:check_auth() end, scram_sha_256_auth = function(self, msg) - assert(self.config.password, "the database is requesting a password for authentication but you did not provide a password") + assert(self.config.password, "missing password, required for connect") local random_bytes, x509_digest do local _obj_0 = require("pgmoon.crypto") diff --git a/src/test.lua b/src/test.lua index 151bfdf..51ab976 100644 --- a/src/test.lua +++ b/src/test.lua @@ -1,22 +1,66 @@ -require("mobdebug").start("127.0.0.1") +local cjson = require('cjson') +local pgmoon = require('pgmoon'); ---用于接收前端数据的对象 -local args = nil ---获取前端的请求方式 并获取传递的参数 -local request_method = ngx.var.request_method ---判断是get请求还是post请求并分别拿出相应的数据 -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() - --兼容请求使用post请求,但是传参以get方式传造成的无法获取到数据的bug - if (args == nil or args.data == null) then - args = ngx.req.get_uri_args() - end +-- 配置数据库连接 +local config = { + host = "127.0.0.1", -- postgres host + port = 5432, -- postgres port + user = "postgres", + password = "1qaz2wsx", -- postgres password + database = "postgres" +} + +-- 创建一个新的连接 +local conn = pgmoon.new(config) + +-- 连接到数据库 +conn:connect(function(err) + if err then + print("Error connecting to database:", err) + else + print("Connected to the PostgreSQL server.") + + -- 执行一个简单的查询 + conn:query("SELECT version()") + :on_data(function(row) + print("Database Version:", row[1]) + end) + :on_error(function(err) + print("Query Error:", err) + end) + :on_finish(function() + print("Query finished.") + -- 关闭连接 + conn:close() + end) + end +end) + +local function test() + -- 创建数据库连接对象 + local db = pgmoon.new(config) + local ok, err = db:connect() + if not ok then + error("Connection failed: " .. err) + end + + ngx.say("Connection success") + -- 执行查询 + local res, err = db:query("SELECT * FROM tbl_user") + if not res then + error("Query failed: " .. err) + end + ngx.say(err) + for _, row in ipairs(res) do + for key, value in pairs(row) do + ngx.say(key .. ":" .. value) + end + end + --local rest, err1 = db:query("SELECT version()") + --ngx.say(rest) + + --关闭数据库 + db:disconnect() end ---获取前端传递的name值 -local name = args.name ---响应前端 -ngx.say("hello:"..name) \ No newline at end of file +test() \ No newline at end of file