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获取组织架构信息