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
2029ef9b
Commit
2029ef9b
authored
Jan 11, 2018
by
xzj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持_ip_参数,重写请求
parent
76c67b5d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
index.js
index.js
+14
-0
package.json
package.json
+1
-1
No files found.
index.js
View file @
2029ef9b
'
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
;
...
@@ -48,6 +49,11 @@ module.exports = function (options) {
...
@@ -48,6 +49,11 @@ 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
();
...
@@ -67,6 +73,10 @@ module.exports = function (options) {
...
@@ -67,6 +73,10 @@ 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_
'
])
{
option
.
url
=
rewriteUrl
(
option
.
url
,
ctx
.
request
.
query
[
'
_ip_
'
])
}
debug
(
option
)
debug
(
option
)
if
(
!
option
.
agent
&&
!
/^https/
.
test
(
option
.
url
))
{
if
(
!
option
.
agent
&&
!
/^https/
.
test
(
option
.
url
))
{
...
@@ -100,6 +110,10 @@ module.exports = function (options) {
...
@@ -100,6 +110,10 @@ module.exports = function (options) {
}
}
option
=
Object
.
assign
({},
pipeDefault
,
option
)
option
=
Object
.
assign
({},
pipeDefault
,
option
)
if
(
!
isProduction
&&
ctx
.
request
.
query
[
'
_ip_
'
])
{
option
.
url
=
rewriteUrl
(
option
.
url
,
ctx
.
request
.
query
[
'
_ip_
'
])
}
if
(
!
option
.
method
)
{
if
(
!
option
.
method
)
{
option
.
method
=
ctx
.
method
option
.
method
=
ctx
.
method
}
}
...
...
package.json
View file @
2029ef9b
{
{
"name"
:
"request-proxy"
,
"name"
:
"request-proxy"
,
"version"
:
"1.0.
4
"
,
"version"
:
"1.0.
5
"
,
"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