update
Browse files- Dockerfile +2 -1
- app.lua +1 -0
- app/v1/app.lua +60 -0
Dockerfile
CHANGED
|
@@ -29,7 +29,8 @@ USER myuser
|
|
| 29 |
|
| 30 |
# 复制Lua脚本和nginx配置文件到容器中
|
| 31 |
COPY app.lua /data/myapp/
|
| 32 |
-
COPY app_v1.lua /data/myapp/
|
|
|
|
| 33 |
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
|
| 34 |
|
| 35 |
# 指定容器启动时运行的命令
|
|
|
|
| 29 |
|
| 30 |
# 复制Lua脚本和nginx配置文件到容器中
|
| 31 |
COPY app.lua /data/myapp/
|
| 32 |
+
# COPY app_v1.lua /data/myapp/
|
| 33 |
+
COPY app /data/myapp/
|
| 34 |
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
|
| 35 |
|
| 36 |
# 指定容器启动时运行的命令
|
app.lua
CHANGED
|
@@ -29,6 +29,7 @@ ngx.say("pass_url: ", pass_url)
|
|
| 29 |
-- require(lua_path)
|
| 30 |
local lua_path = "app/" ..api_version .. "/app"
|
| 31 |
ngx.say("lua_path: ", lua_path)
|
|
|
|
| 32 |
|
| 33 |
-- local lfs = require("lfs")
|
| 34 |
-- -- 获取当前工作目录
|
|
|
|
| 29 |
-- require(lua_path)
|
| 30 |
local lua_path = "app/" ..api_version .. "/app"
|
| 31 |
ngx.say("lua_path: ", lua_path)
|
| 32 |
+
require(lua_path)
|
| 33 |
|
| 34 |
-- local lfs = require("lfs")
|
| 35 |
-- -- 获取当前工作目录
|
app/v1/app.lua
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
-- 根据版本号加载不同的 Lua 文件
|
| 27 |
+
-- local lua_path = "app_" .. api_version
|
| 28 |
+
-- ngx.say("lua_path: ", lua_path)
|
| 29 |
+
-- require(lua_path)
|
| 30 |
+
local lua_path = "app/" ..api_version .. "/app"
|
| 31 |
+
ngx.say("lua_path: ", lua_path)
|
| 32 |
+
require(lua_path)
|
| 33 |
+
|
| 34 |
+
-- local lfs = require("lfs")
|
| 35 |
+
-- -- 获取当前工作目录
|
| 36 |
+
-- local current_dir = lfs.currentdir()
|
| 37 |
+
-- ngx.say("Current directory:", current_dir)
|
| 38 |
+
-- -- 列举当前目录的内容
|
| 39 |
+
-- for file in lfs.dir(current_dir) do
|
| 40 |
+
-- if file ~= "." and file ~= ".." then -- 排除 "." 和 ".."
|
| 41 |
+
-- local path = current_dir .. "/" .. file
|
| 42 |
+
-- local attr = lfs.attributes(path) -- 获取文件属性
|
| 43 |
+
|
| 44 |
+
-- if attr.mode == "directory" then
|
| 45 |
+
-- print("Directory:", file)
|
| 46 |
+
-- elseif attr.mode == "file" then
|
| 47 |
+
-- print("File:", file)
|
| 48 |
+
-- else
|
| 49 |
+
-- print("Other:", file)
|
| 50 |
+
-- end
|
| 51 |
+
-- end
|
| 52 |
+
-- end
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
-- local status, err = pcall(require, lua_path)
|
| 56 |
+
-- if not status then
|
| 57 |
+
-- ngx.log(ngx.ERR, "failed to load lua file: ", lua_path, ", error: ", err)
|
| 58 |
+
-- ngx.say("Error: Failed to load API version: ", api_version)
|
| 59 |
+
-- ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
|
| 60 |
+
-- end
|