geqintan commited on
Commit
bbf08b3
·
1 Parent(s): 2a934a7
Files changed (1) hide show
  1. app.lua +19 -19
app.lua CHANGED
@@ -6,27 +6,27 @@
6
  ]]
7
  local uri = ngx.var.uri
8
  ngx.say("uri: [", uri)
 
 
 
 
 
9
  if uri == '/' then
10
- ngx.say("uri = /")
11
- os.exit()
 
 
 
 
 
 
 
 
 
12
  end
13
- -- os.exit()
14
- -- print(uri)
15
- -- print('adf')
16
- -- os.exit()
17
- -- -- if uri == '/' then
18
- -- -- os.exit() -- 终止整个程序
19
- -- -- end
20
-
21
- -- -- 使用正则表达式匹配路径中的变量
22
- -- local api_version, api_pxoxy_pass_url_indicator = uri:match("/(v%d+)/(.+)")
23
-
24
- -- ngx.say("api_version: ", api_version)
25
- -- ngx.say("api_pxoxy_pass_url_indicator: ", api_pxoxy_pass_url_indicator)
26
- -- pass_url = api_pxoxy_pass_url_indicator
27
- -- pass_url = pass_url:gsub("^http/", "http://")
28
- -- pass_url = pass_url:gsub("^https/", "https://")
29
- -- ngx.say("pass_url: ", pass_url)
30
 
31
  -- ngx.say('\n\n\n')
32
 
 
6
  ]]
7
  local uri = ngx.var.uri
8
  ngx.say("uri: [", uri)
9
+
10
+ local api_version = ''
11
+ local api_pxoxy_pass_url_indicator = ''
12
+
13
+ -- 提取版本号和 proxy_pass url 标识
14
  if uri == '/' then
15
+ ngx.say("uri = /")
16
+ ngx.exit(ngx.HTTP_OK)
17
+ else
18
+ local version_match = string.match(uri, "^(v%d+)/(.*)")
19
+ if version_match then
20
+ api_version = version_match[1]
21
+ api_pxoxy_pass_url_indicator = version_match[2]
22
+ else
23
+ api_version = ''
24
+ api_pxoxy_pass_url_indicator = ''
25
+ end
26
  end
27
+
28
+ ngx.say("api_version: ", api_version)
29
+ ngx.say("api_pxoxy_pass_url_indicator: ", api_pxoxy_pass_url_indicator)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  -- ngx.say('\n\n\n')
32