Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
request-proxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
request-proxy
Commits
5dce753f
Commit
5dce753f
authored
Jan 17, 2018
by
xzj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一参数为uri;write逻辑移到v2版本中
parent
6c8b87b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
30 deletions
+8
-30
README.md
README.md
+2
-2
index.js
index.js
+5
-27
package.json
package.json
+1
-1
No files found.
README.md
View file @
5dce753f
...
@@ -48,7 +48,7 @@ module.exports = router
...
@@ -48,7 +48,7 @@ module.exports = router
pipe
pipe
option: 对象格式,和request包参数一直
option: 对象格式,和request包参数一直
如果是字符串类型,默认会转为{ur
l
: 'some string'}
如果是字符串类型,默认会转为{ur
i
: 'some string'}
extra: 对象格式,现有两个属性
extra: 对象格式,现有两个属性
rawRes: 是否返回接受到的res,默认false
rawRes: 是否返回接受到的res,默认false
...
@@ -63,7 +63,7 @@ extra: 对象格式,现有两个属性
...
@@ -63,7 +63,7 @@ extra: 对象格式,现有两个属性
if (ctx.method === 'POST') {
if (ctx.method === 'POST') {
let option = {
let option = {
ur
l
: config.api.mall_api + ctx.url.replace('/mall/other', ''),
ur
i
: config.api.mall_api + ctx.url.replace('/mall/other', ''),
headers: {
headers: {
'x-auth-token': ctx.headers['x-auth-token']
'x-auth-token': ctx.headers['x-auth-token']
}
}
...
...
index.js
View file @
5dce753f
'
use strict
'
'
use strict
'
const
request
=
require
(
'
request
'
)
const
request
=
require
(
'
request
'
)
const
debug
=
require
(
'
debug
'
)(
'
request-proxy
'
)
const
debug
=
require
(
'
debug
'
)(
'
request-proxy
'
)
const
qs
=
require
(
'
querystring
'
)
const
Agent
=
require
(
'
agentkeepalive
'
);
const
Agent
=
require
(
'
agentkeepalive
'
);
const
HttpsAgent
=
require
(
'
agentkeepalive
'
).
HttpsAgent
;
const
HttpsAgent
=
require
(
'
agentkeepalive
'
).
HttpsAgent
;
...
@@ -49,11 +48,6 @@ module.exports = function (options) {
...
@@ -49,11 +48,6 @@ module.exports = function (options) {
timeout
:
options
.
timeout
timeout
:
options
.
timeout
}
}
const
isProduction
=
process
.
env
.
NODE_ENV
===
'
production
'
const
rewriteUrl
=
function
(
source
,
to
)
{
return
source
.
replace
(
/
\/\/([^\/]
+
)\/
/
,
`//
${
to
}
/`
).
replace
(
/_ip_=
[\w\.
:%
]
+&
?
/
,
''
)
}
const
httpAgent
=
new
Agent
(
options
.
agent
);
const
httpAgent
=
new
Agent
(
options
.
agent
);
const
httpsAgent
=
new
HttpsAgent
();
const
httpsAgent
=
new
HttpsAgent
();
...
@@ -73,19 +67,11 @@ module.exports = function (options) {
...
@@ -73,19 +67,11 @@ module.exports = function (options) {
option
=
Object
.
assign
({},
curlDefault
,
option
)
option
=
Object
.
assign
({},
curlDefault
,
option
)
extra
=
Object
.
assign
({},
extraDefault
,
extra
)
extra
=
Object
.
assign
({},
extraDefault
,
extra
)
if
(
!
isProduction
&&
ctx
.
request
.
query
[
'
_ip_
'
])
{
if
(
option
.
url
)
{
option
.
url
=
rewriteUrl
(
option
.
url
,
ctx
.
request
.
query
[
'
_ip_
'
])
}
else
{
option
.
uri
=
rewriteUrl
(
option
.
uri
,
ctx
.
request
.
query
[
'
_ip_
'
])
}
}
debug
(
option
)
debug
(
option
)
if
(
!
option
.
agent
&&
!
/^https/
.
test
(
option
.
ur
l
))
{
if
(
!
option
.
agent
&&
!
/^https/
.
test
(
option
.
ur
i
))
{
option
.
agent
=
httpAgent
option
.
agent
=
httpAgent
}
else
if
(
!
option
.
agent
&&
/^https/
.
test
(
option
.
ur
l
))
{
}
else
if
(
!
option
.
agent
&&
/^https/
.
test
(
option
.
ur
i
))
{
option
.
agent
=
httpsAgent
option
.
agent
=
httpsAgent
}
}
...
@@ -114,29 +100,21 @@ module.exports = function (options) {
...
@@ -114,29 +100,21 @@ module.exports = function (options) {
}
}
option
=
Object
.
assign
({},
pipeDefault
,
option
)
option
=
Object
.
assign
({},
pipeDefault
,
option
)
if
(
!
isProduction
&&
ctx
.
request
.
query
[
'
_ip_
'
])
{
if
(
option
.
url
)
{
option
.
url
=
rewriteUrl
(
option
.
url
,
ctx
.
request
.
query
[
'
_ip_
'
])
}
else
{
option
.
uri
=
rewriteUrl
(
option
.
uri
,
ctx
.
request
.
query
[
'
_ip_
'
])
}
}
if
(
!
option
.
method
)
{
if
(
!
option
.
method
)
{
option
.
method
=
ctx
.
method
option
.
method
=
ctx
.
method
}
}
debug
(
option
)
debug
(
option
)
if
(
!
option
.
agent
&&
!
/^https/
.
test
(
option
.
ur
l
))
{
if
(
!
option
.
agent
&&
!
/^https/
.
test
(
option
.
ur
i
))
{
option
.
agent
=
httpAgent
option
.
agent
=
httpAgent
}
else
if
(
!
option
.
agent
&&
/^https/
.
test
(
option
.
ur
l
))
{
}
else
if
(
!
option
.
agent
&&
/^https/
.
test
(
option
.
ur
i
))
{
option
.
agent
=
httpsAgent
option
.
agent
=
httpsAgent
}
}
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
let
r
=
ctx
.
req
.
pipe
(
request
(
option
,
function
(
err
,
response
)
{
let
r
=
ctx
.
req
.
pipe
(
request
(
option
,
function
(
err
,
response
)
{
if
(
option
.
time
&&
options
.
logger
)
{
if
(
option
.
time
&&
options
.
logger
)
{
options
.
logger
.
info
(
option
.
ur
l
||
option
.
ur
i
,
JSON
.
stringify
(
response
&&
response
.
timings
||
''
))
options
.
logger
.
info
(
option
.
uri
,
JSON
.
stringify
(
response
&&
response
.
timings
||
''
))
}
}
}))
}))
r
.
on
(
'
error
'
,
function
(
err
)
{
r
.
on
(
'
error
'
,
function
(
err
)
{
...
...
package.json
View file @
5dce753f
{
{
"name"
:
"request-proxy"
,
"name"
:
"request-proxy"
,
"version"
:
"1.
1.2
"
,
"version"
:
"1.
2.0
"
,
"description"
:
""
,
"description"
:
""
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment