Skip to content

Commit eea9876

Browse files
committed
feat: 支持静态资源路由配置 feat: 补充文档 feat: 优化部分代码和注释
1 parent f7bf676 commit eea9876

30 files changed

+884
-70
lines changed

balance/tl_ops_balance_core_api.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ local cjson = require("cjson.safe");
88
local cache_api = require("cache.tl_ops_cache_core"):new("tl-ops-balance-api");
99
local tl_ops_utils_func = require("utils.tl_ops_utils_func");
1010
local tl_ops_constant_balance_api = require("constant.tl_ops_constant_balance_api");
11-
local tl_ops_match_mode = require("constant.tl_ops_constant_comm").tl_ops_match_mode;
12-
local tl_ops_constant_health = require("constant.tl_ops_constant_health")
13-
local shared = ngx.shared.tlopsbalance
14-
local find = ngx.re.find
15-
11+
local tl_ops_constant_comm = require("constant.tl_ops_constant_comm");
12+
local tl_ops_constant_health = require("constant.tl_ops_constant_health");
13+
local tl_ops_match_mode = tl_ops_constant_comm.tl_ops_match_mode;
14+
local tl_ops_api_type = tl_ops_constant_comm.tl_ops_api_type;
15+
local shared = ngx.shared.tlopsbalance;
16+
local find = ngx.re.find;
1617

1718
-- 处理匹配逻辑
1819
local tl_ops_balance_api_matcher_mode = function (matcher, request_uri, obj)
@@ -81,6 +82,7 @@ end
8182

8283

8384
local tl_ops_balance_api_service_matcher = function(service_list_table)
85+
8486
local matcher = nil
8587
local node = nil
8688

@@ -153,15 +155,26 @@ local tl_ops_balance_api_service_matcher = function(service_list_table)
153155
local node_state , _ = shared:get(key)
154156

155157

158+
-- 静态页面代理路径
159+
local api_type = matcher.api_type
160+
if api_type and api_type == tl_ops_api_type.page then
161+
ngx.req.set_uri_args({
162+
url = request_uri
163+
})
164+
ngx.req.set_uri("/pageproxy", true)
165+
return
166+
end
167+
156168
-- 需要重写url
157169
local rewrite_url = matcher.rewrite_url
158170
if rewrite_url and rewrite_url ~= '' then
159171
ngx.req.set_uri(rewrite_url, false)
172+
return
160173
end
161174

162-
-- 需要转发到服务具体路径
175+
-- 需要转发到服务下的具体路径
163176
local fake_prefix = matcher.fake_prefix
164-
if fake_prefix and matcher.fake_prefix ~= '' then
177+
if fake_prefix and fake_prefix ~= '' then
165178
-- 通过虚拟前缀截取后缀
166179
local fake_sub = string.sub(request_uri, #fake_prefix + 1, #request_uri)
167180
if fake_sub then

bin/install_centeros.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
66
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
77
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
88
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
9-
TL_OPS_VER="v3.2.0"
9+
TL_OPS_VER="v3.3.0"
1010

1111
echo_msg(){
1212
cur_time=$(date "+%Y-%m-%d %H:%M:%S")

bin/install_ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TL_OPS_PATH="/usr/local/tl-ops-manage/"
66
TL_OPS_CONF_PATH="/usr/local/tl-ops-manage/conf/tl_ops_manage.conf"
77
TL_OPS_LUA_PATH="/usr/local/openresty/lualib/?.lua;;/usr/local/tl-ops-manage/?.lua;;"
88
TL_OPS_LUAC_PATH="/usr/local/openresty/lualib/?.so;;"
9-
TL_OPS_VER="v3.2.0"
9+
TL_OPS_VER="v3.3.0"
1010

1111
echo_msg(){
1212
cur_time=$(date "+%Y-%m-%d %H:%M:%S")

conf/tl_ops_manage.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ server {
6666
}
6767
}
6868

69+
location = /pageproxy {
70+
set $pageproxy "";
71+
alias $pageproxy;
72+
rewrite_by_lua_block {
73+
tlops:tl_ops_process_init_rewrite('onlyplugin');
74+
}
75+
}
76+
6977
location /balanceerr/ {
7078
content_by_lua_block {
7179
tlops:tl_ops_process_init_content();

constant/tl_ops_constant_balance_api.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local match_mode = require("constant.tl_ops_constant_comm").tl_ops_match_mode;
2+
local api_type = require("constant.tl_ops_constant_comm").tl_ops_api_type;
23

34
-- api 默认列表
45
local tl_ops_constant_balance_api = {
@@ -23,6 +24,7 @@ local tl_ops_constant_balance_api = {
2324
host = "tlops1.com", -- 当前url处理的域名范围
2425
rewrite_url = "", -- 当前url重写后的url
2526
fake_prefix = "", -- 当前uri规则的虚拟前缀
27+
api_type = api_type.api, -- 当前uri规则的类型
2628
},
2729
random = {
2830
id = 1,
@@ -32,6 +34,7 @@ local tl_ops_constant_balance_api = {
3234
host = "tlops1.com", -- 当前url处理的域名范围
3335
rewrite_url = "", -- 当前url重写后的url
3436
fake_prefix = "", -- 当前uri规则的虚拟前缀
37+
api_type = api_type.api, -- 当前uri规则的类型
3538
}
3639
},
3740
rule = {-- api rule 策略

constant/tl_ops_constant_comm.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
local tl_ops_constant_comm = {
22
tl_ops_status = {-- service status 状态
3+
-- 在线
34
online = 0,
5+
-- 下线
46
offline = 1,
7+
-- 错误
58
error = 2
69
},
710
tl_ops_rt = {-- rt 返回值
11+
-- 成功
812
ok = 0,
13+
-- 错误
914
error = -1,
15+
-- 参数有误
1016
args_error = -2,
17+
-- 找不到
1118
not_found = -3,
19+
-- 解析错误
1220
parse_error = -4
1321
},
1422
tl_ops_match_mode = {-- api匹配模式
@@ -20,6 +28,12 @@ local tl_ops_constant_comm = {
2028
regi = "joi",
2129
-- 最长字符串匹配
2230
regid = "joid"
31+
},
32+
tl_ops_api_type = {-- api类型
33+
-- 接口类型
34+
api = "api",
35+
-- 文件资源
36+
page = "page"
2337
}
2438
};
2539

doc/change.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11

22
## 事务更新日程
33

4+
2023-03-05
5+
6+
1. 支持静态资源路由配置
7+
8+
2. 同步补充文档
9+
10+
3. 优化部分代码
11+
12+
4. 事务日程调整
13+
14+
415
2023-02-27
516

617
1. 支持api路由指定虚拟前缀

err/tl_ops_err_content.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- @author iamtsm
55
-- @email 1905333456@qq.com
66

7-
local tl_ops_err_content_core = require(".err.tl_ops_err_content_core");
7+
local tl_ops_err_content_core = require("err.tl_ops_err_content_core");
88

99
local _M = {}
1010

gitbook/SUMMARY.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949

5050
* [多规则匹配](code/balance/README_RULE.md)
5151

52-
* [多模式匹配](code/balance/README_RULE.md)
53-
5452
* [路由统计](code/balancecount/README.md)
5553

5654
* [动态配置](code/dynamic/README.md)

gitbook/code/pageproxy/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ location xxx {
3030

3131
#### 动态调整路径
3232

33-
还有一个好处就是支持动态调整静态资源路径,当然,前提是你已经支持了可视化操作修改路径
34-
33+
还有一个好处就是支持动态调整静态资源路径,v-3.3.0以上已支持动态配置静态资源路由
3534

3635
## 实现
3736

0 commit comments

Comments
 (0)