-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 支持静态资源路由配置 feat: 补充文档 feat: 优化部分代码和注释
- Loading branch information
Showing
30 changed files
with
884 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
|
||
## 事务更新日程 | ||
|
||
2023-03-05 | ||
|
||
1. 支持静态资源路由配置 | ||
|
||
2. 同步补充文档 | ||
|
||
3. 优化部分代码 | ||
|
||
4. 事务日程调整 | ||
|
||
|
||
2023-02-27 | ||
|
||
1. 支持api路由指定虚拟前缀 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
-- @author iamtsm | ||
-- @email [email protected] | ||
|
||
local tl_ops_err_content_core = require(".err.tl_ops_err_content_core"); | ||
local tl_ops_err_content_core = require("err.tl_ops_err_content_core"); | ||
|
||
local _M = {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
-- tl_ops_set_page_proxy_export | ||
-- en : set export page_proxy config | ||
-- zn : 更新log_analyze插件配置管理 | ||
-- zn : 更新page_proxy插件配置管理 | ||
-- @author iamtsm | ||
-- @email [email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
-- tl_ops_page_proxy_get | ||
-- en : get page_proxy config list | ||
-- zn : 获取page_proxy配置列表 | ||
-- @author iamtsm | ||
-- @email [email protected] | ||
|
||
local cache = require("cache.tl_ops_cache_core"):new("tl-ops-page-proxy"); | ||
local constant = require("plugins.tl_ops_page_proxy.tl_ops_plugin_constant"); | ||
local tl_ops_rt = tlops.constant.comm.tl_ops_rt; | ||
local tl_ops_utils_func = tlops.utils | ||
local cjson = require("cjson.safe"); | ||
cjson.encode_empty_table_as_object(false) | ||
|
||
|
||
local Router = function() | ||
|
||
local list_str, _ = cache:get(constant.cache_key.list); | ||
if not list_str or list_str == nil then | ||
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.not_found, "not found list", _); | ||
return; | ||
end | ||
|
||
|
||
local res_data = {} | ||
res_data[constant.cache_key.list] = cjson.decode(list_str) | ||
|
||
tl_ops_utils_func:set_ngx_req_return_ok(tl_ops_rt.ok, "success", res_data); | ||
end | ||
|
||
return Router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
-- tl_ops_page_proxy | ||
-- en : page_proxy | ||
-- zn : 静态页面代理实现 | ||
-- @author iamtsm | ||
-- @email [email protected] | ||
|
||
local constant = require("plugins.tl_ops_page_proxy.tl_ops_plugin_constant"); | ||
local cache = require("cache.tl_ops_cache_core"):new("tl-ops-page-proxy"); | ||
local tlog = require("utils.tl_ops_utils_log"):new("tl_ops_plugin_page_proxy"); | ||
local env = tlops.env | ||
local cjson = require("cjson.safe") | ||
cjson.encode_empty_table_as_object(false) | ||
|
||
local _M = { | ||
_VERSION = '0.01', | ||
} | ||
local mt = { __index = _M } | ||
|
||
|
||
-- 加载静态页面路由配置 | ||
local get_page_proxy_cache = function( request_uri, api ) | ||
local list_str, _ = cache:get(constant.cache_key.list); | ||
if not list_str or list_str == nil then | ||
return nil | ||
end | ||
|
||
local list = cjson.decode(list_str) | ||
if not list then | ||
return nil | ||
end | ||
|
||
for i = 1, #list do | ||
local data = list[i] | ||
if ngx.re.find(api, data.api, 'jo') then | ||
return data | ||
end | ||
end | ||
|
||
return nil | ||
end | ||
|
||
-- 核心逻辑 | ||
function _M:page_proxy_core(ctx) | ||
|
||
-- 请求uri | ||
local request_uri = ctx.request_uri | ||
-- 参数 | ||
local args = ngx.req.get_uri_args() | ||
|
||
if ngx.re.find(request_uri, "/tlopsmanage/", 'jo') then | ||
ngx.var.tlopsmanage = env.path.tlopsmanage | ||
return true, "ok" | ||
end | ||
|
||
if ngx.re.find(request_uri, "/website/", 'jo') then | ||
ngx.var.website = env.path.website | ||
return true, "ok" | ||
end | ||
|
||
-- 静态页面代理路径 | ||
if args.url then | ||
local match = get_page_proxy_cache(request_uri, args.url); | ||
if match and match.path then | ||
ngx.var.pageproxy = match.path .. args.url; | ||
tlog:dbg("page_proxy match : ",match, ", args : ", args, ",request_uri : ",request_uri) | ||
else | ||
tlog:dbg("page_proxy not match : ",match, ", args : ", args, ",request_uri : ",request_uri) | ||
ngx.exit(404) | ||
return true, "ok" | ||
end | ||
end | ||
|
||
tlog:dbg("page_proxy plugin ok ") | ||
|
||
return true, "ok" | ||
end | ||
|
||
|
||
function _M:new() | ||
return setmetatable({}, mt) | ||
end | ||
|
||
return _M |
Oops, something went wrong.