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
c0039350
Commit
c0039350
authored
Jan 17, 2018
by
xzj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统一参数为uri;write逻辑移到v2版本中
parent
6c8b87b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
28 deletions
+6
-28
index.js
index.js
+5
-27
package.json
package.json
+1
-1
No files found.
index.js
View file @
c0039350
'
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 @
c0039350
{
{
"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