Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-portal-fe
·
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
周奇琪
9 years ago
Commit
6727519d48847ca36ba2376ba4153df3bae5326f
1 parent
a6536229
修复上传文件失败的问题
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
server/mid/grayroute.js
server/mid/grayroute.js
View file @
6727519
...
...
@@ -6,6 +6,7 @@ var request = require('request');
var
config
=
require
(
'../config/gray'
);
var
_
=
require
(
'lodash'
);
var
fs
=
require
(
'fs'
);
/**
* 灰度界面配置
...
...
@@ -31,8 +32,7 @@ module.exports = function(proxyRoute) {
}
//如果新系统路由没有,代理到老平台
if
(
!
proxyRoute
.
interfacesConfig
[
key
])
{
if
(
!
proxyRoute
.
interfacesConfig
[
key
])
{
//老系统调用地址
var
callUrl
=
config
.
url
+
req
.
originalUrl
;
var
options
=
{
...
...
@@ -53,9 +53,12 @@ module.exports = function(proxyRoute) {
}
else
{
options
.
headers
[
'cookie'
]
=
req
.
session
.
gray
;
}
if
(
req
.
files
&&
_
.
keys
(
req
.
files
).
length
>
0
)
{
options
.
formData
=
addFiles
(
req
);
delete
options
.
form
;
}
logger
.
log
(
'info'
,
'grayroute: request options: %j'
,
options
,{});
//发起代理请求
if
(
req
.
headers
[
'accept'
].
indexOf
(
'text/html'
)
>-
1
||
req
.
xhr
)
{
request
(
options
,
function
(
err
,
res
,
body
)
{
...
...
@@ -87,4 +90,17 @@ module.exports = function(proxyRoute) {
next
();
}
}
}
/**
* 添加文件到body中
* @param {Object} req 请求对象
*/
function
addFiles
(
req
)
{
var
body
=
{};
_
.
forEach
(
req
.
files
,
function
(
v
,
k
){
body
[
k
]
=
fs
.
createReadStream
(
v
.
path
);
});
_
.
merge
(
body
,
req
.
body
);
return
body
;
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment