update
Browse files- app copy.lua +29 -0
- app.lua +8 -2
app copy.lua
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- 这是一个单行注释
|
| 2 |
+
|
| 3 |
+
--[[
|
| 4 |
+
这是一个多行注释
|
| 5 |
+
这是一个多行注释
|
| 6 |
+
]]
|
| 7 |
+
local uri = ngx.var.uri
|
| 8 |
+
|
| 9 |
+
local api_version = ''
|
| 10 |
+
local api_pxoxy_pass_url_indicator = ''
|
| 11 |
+
|
| 12 |
+
-- 提取版本号和 proxy_pass url 标识
|
| 13 |
+
if uri == '/' then -- uri为 / ,退出运行
|
| 14 |
+
ngx.exit(ngx.HTTP_OK)
|
| 15 |
+
end
|
| 16 |
+
|
| 17 |
+
local api_version, api_pxoxy_pass_url_indicator = uri:match("/([^/]+)/(.*)")
|
| 18 |
+
|
| 19 |
+
ngx.say("api_version: ", api_version)
|
| 20 |
+
ngx.say("api_pxoxy_pass_url_indicator: ", api_pxoxy_pass_url_indicator)
|
| 21 |
+
pass_url = api_pxoxy_pass_url_indicator
|
| 22 |
+
pass_url = pass_url:gsub("http/", "http://")
|
| 23 |
+
pass_url = pass_url:gsub("https/", "https://")
|
| 24 |
+
ngx.say("pass_url: ", pass_url)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
app.lua
CHANGED
|
@@ -23,5 +23,11 @@ pass_url = pass_url:gsub("http/", "http://")
|
|
| 23 |
pass_url = pass_url:gsub("https/", "https://")
|
| 24 |
ngx.say("pass_url: ", pass_url)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
pass_url = pass_url:gsub("https/", "https://")
|
| 24 |
ngx.say("pass_url: ", pass_url)
|
| 25 |
|
| 26 |
+
-- 根据版本号加载不同的 Lua 文件
|
| 27 |
+
local lua_path = "app/" .. api_version .. "/app"
|
| 28 |
+
local status, err = pcall(require, lua_path)
|
| 29 |
+
if not status then
|
| 30 |
+
ngx.log(ngx.ERR, "failed to load lua file: ", lua_path, ", error: ", err)
|
| 31 |
+
ngx.say("Error: Failed to load API version: ", api_version)
|
| 32 |
+
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
|
| 33 |
+
end
|