Download app.lua from tanbushi/apis-prd: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/tanbushi/apis-prd/resolve/main/app.lua
- Command line
-
hf download hf://spaces/tanbushi/apis-prd/app.lua
-
curl -L -o app.lua https://huggingface.co/spaces/tanbushi/apis-prd/resolve/main/app.lua
1.37 kB
| -- 这是一个单行注释 | |
| --[[ | |
| 这是一个多行注释 | |
| 这是一个多行注释 | |
| ]] | |
| local uri = ngx.var.uri | |
| local api_version = '' | |
| local api_pxoxy_pass_url_indicator = '' | |
| -- 提取版本号和 proxy_pass url 标识 | |
| if uri == '/' then -- uri为 / ,退出运行 | |
| ngx.exit(ngx.HTTP_OK) | |
| end | |
| local api_version, api_pxoxy_pass_url_indicator = uri:match("/?([^/]+)/?(.*)") | |
| ngx.say("api_version: ", api_version) | |
| ngx.say("api_pxoxy_pass_url_indicator: ", api_pxoxy_pass_url_indicator) | |
| pass_url = api_pxoxy_pass_url_indicator | |
| -- local upstream_dict = ngx.shared.upstream_dict | |
| -- upstream_dict:set("upstream", pass_url) | |
| pass_url = pass_url:gsub("http/", "http://") | |
| pass_url = pass_url:gsub("https/", "https://") | |
| ngx.say("pass_url: ", pass_url) | |
| -- 根据版本号加载不同的 Lua 文件 | |
| -- local lua_path = "app_" .. api_version | |
| -- ngx.say("lua_path: ", lua_path) | |
| -- require(lua_path) | |
| local lua_path = "app/" ..api_version .. "/app" | |
| ngx.say("lua_path: ", lua_path) | |
| module = require("app/" .. api_version .. "/app") --require 是没问题的 | |
| -- 检查模块是否加载成功 | |
| if type(module) ~= "table" then | |
| ngx.say("Error: Failed to load module") | |
| ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR) | |
| end | |
| -- 调用模块中的函数 | |
| module.some_function() -- 调用 some_function | |
| module.another_function() -- 调用 another_function | |
| ngx.say("module.a: ", module.a) | |