Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
yoho-ansible-roles
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
chunhua.zhang
6 years ago
Commit
a513d1c54ba52349f6bb91ba393b3ba64879c467
1 parent
0cb3a659
add
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
8 deletions
roles/openresty/files/java-nginx-config/nginx/conf/lua/switch_controller.lua
roles/openresty/files/java-nginx-config/nginx/conf/redirect.lua
roles/openresty/files/java-nginx-config/nginx/conf/lua/switch_controller.lua
View file @
a513d1c
...
...
@@ -36,5 +36,10 @@ function M:init()
function
M
:
get_percentage
()
return
lua_context
.
lua_conf_cache
:
get
(
"switch:percentage"
)
local
per
=
lua_context
.
lua_conf_cache
:
get
(
"switch:percentage"
)
if
not
per
then
return
0
else
return
tonumber
(
per
)
end
end
...
...
roles/openresty/files/java-nginx-config/nginx/conf/redirect.lua
View file @
a513d1c
...
...
@@ -2,15 +2,16 @@ local http_request = require "http_request"
local
switch_controller
=
require
"switch_controller"
function
do_direct
(
redirect
_p
ath
)
function
do_direct
(
redirect
P
ath
)
local
request_method
=
ngx
.
var
.
request_method
;
if
"GET"
==
request_method
then
ngx
.
exec
(
redirect_p
ath
,
ngx
.
req
.
get_uri_args
());
return
ngx
.
exec
(
redirectP
ath
,
ngx
.
req
.
get_uri_args
());
else
ngx
.
exec
(
redirect_p
ath
);
return
ngx
.
exec
(
redirectP
ath
);
end
end
function
route
(
redirectPath
)
--- modify content-type, add utf-8 charset if absent---
...
...
@@ -19,7 +20,7 @@ function route(redirectPath)
end
--- if url match the service url, just redirect path with uri
if
ngx
.
var
.
service_matched
==
"1"
then
if
ngx
.
var
.
service_matched
and
ngx
.
var
.
service_matched
==
"1"
then
local
uri
=
ngx
.
var
.
uri
if
nil
==
ngx
.
req
.
get_uri_args
()
then
return
ngx
.
exec
(
redirectPath
..
uri
);
...
...
@@ -74,9 +75,9 @@ function main()
local
redirectPath
=
"/apigateway"
;
init_read_body
()
local
percentage
=
switch_controller
.
get_percentage
()
if
percentage
and
percentage
>=
1
then
if
percentage
>=
1
then
local
uid
=
http_request
.
get_req_param
(
"uid"
)
if
not
uid
then
uid
=
0
...
...
@@ -93,4 +94,18 @@ function main()
end
---- run -----
main
()
\ No newline at end of file
status
,
errMsg
=
pcall
(
main
)
if
not
status
then
ngx
.
log
(
ngx
.
ERR
,
"call method [main] failed."
,
errMsg
)
--- default
if
ngx
.
var
.
service_matched
and
ngx
.
var
.
service_matched
==
"1"
then
local
uri
=
ngx
.
var
.
uri
if
nil
==
ngx
.
req
.
get_uri_args
()
then
return
ngx
.
exec
(
redirectPath
..
uri
);
else
return
ngx
.
exec
(
redirectPath
..
uri
,
ngx
.
req
.
get_uri_args
());
end
else
do_direct
(
"/apigateway"
)
end
end
...
...
Please
register
or
login
to post a comment