From 8a994fe9d60e508bec3244326a6ceed03705d52b Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qqcom> Date: Tue, 18 Nov 2025 16:07:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E4=BF=AE=E6=94=B9=E8=B7=A8?= =?UTF-8?q?=E7=AB=99=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BD=BF=E7=94=A8nginx?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=BF=9B=E8=A1=8C=E5=A4=84=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9department=E6=96=87=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/nginx.conf | 19 ++++++------------- src/auth/jwt-auth.lua | 8 ++------ src/service/system/department.lua | 4 +++- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 365d596..0a48745 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -53,19 +53,12 @@ http { set $APP_PATH '/home/frankly/work/AuthPlatform'; # 全局 CORS 配置 访问时允许跨域处理 - access_by_lua_block { - ngx.header["Access-Control-Allow-Origin"] = "*" -- 允许所有源,或者指定特定的源,例如 "http://example.com" - --ngx.header["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS" - ngx.header["Access-Control-Allow-Methods"] = "*" - --ngx.header["Access-Control-Allow-Headers"] = "Content-Type, Authorization" - ngx.header["Access-Control-Allow-Headers"] = "*" - ngx.header["Access-Control-Max-Age"] = 1728000 -- 预检结果缓存时间,单位秒 - print("request_method:", ngx.var.request_method) - if ngx.var.request_method == "OPTIONS" then - ngx.header["Content-Length"] = 0 -- 对于 OPTIONS 请求,内容长度为0 - ngx.status = 204 -- No Content,适用于 OPTIONS 请求的响应状态码 - ngx.exit(ngx.OK) -- 结束请求处理 - end + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS'; + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + + if ($request_method = 'OPTIONS') { + return 204; } #OP端点配置 diff --git a/src/auth/jwt-auth.lua b/src/auth/jwt-auth.lua index 064357f..4752c1e 100644 --- a/src/auth/jwt-auth.lua +++ b/src/auth/jwt-auth.lua @@ -2,6 +2,8 @@ local jwt = require "resty.jwt" local cjson = require("cjson.safe") local jsonschema = require("jsonschema") local conf = require("config") +local status = require("util.status") +local resp = require("util.response") -- 定义一个JSON Schema local schema = { @@ -11,12 +13,6 @@ local schema = { }, required = {"Authorization"} } ---对域检方法类型进行直接返回 -if ngx.var.request_method == "OPTIONS" then - ngx.status = 204 -- No Content,适用于 OPTIONS 请求的响应状态码 - ngx.exit(ngx.OK) -- 结束请求处理 -end - --获取用户认证数据信息 local auth_header = ngx.var.http_Authorization diff --git a/src/service/system/department.lua b/src/service/system/department.lua index 4e04424..d570a02 100644 --- a/src/service/system/department.lua +++ b/src/service/system/department.lua @@ -22,7 +22,9 @@ function _M.getSystemDepartments() ngx.exit(ngx.HTTP_FORBIDDEN) end local code, ret = departmentDao.getSystemDepartments() - resp:response(code, ret) + local state = status.SUCCESS + if code ~= 0 then state = status.DATA_IS_WRONG end + resp: response(state, ret) end --根据组织id获取组织架构信息