...
|
...
|
@@ -55,7 +55,7 @@ module.exports = (req, res, next) => { |
|
|
platform_id: config.platform,
|
|
|
userId: req.user.uid
|
|
|
};
|
|
|
let reqParams = Object.assign({
|
|
|
let reqOptions = Object.assign({
|
|
|
url: apiUrl,
|
|
|
method: req.method.toLowerCase(),
|
|
|
headers: {
|
...
|
...
|
@@ -64,26 +64,30 @@ module.exports = (req, res, next) => { |
|
|
'Content-Type': 'application/json'
|
|
|
}
|
|
|
});
|
|
|
let reqParams = Object.assign({}, req.query, req.body);
|
|
|
let files = req.files && req.files.file || [];
|
|
|
|
|
|
if (!_.isArray(files)) {
|
|
|
files = [files];
|
|
|
}
|
|
|
if (reqParams.platform_id) {
|
|
|
delete baseParams.platform_id;
|
|
|
}
|
|
|
|
|
|
if (req.method.toLowerCase() === 'get') {
|
|
|
reqParams.qs = Object.assign({}, req.query, req.body, baseParams);
|
|
|
reqOptions.qs = Object.assign(reqParams, baseParams);
|
|
|
} else if (files.length) {
|
|
|
let reqFiles = {};
|
|
|
|
|
|
_.each(files, file => {
|
|
|
reqFiles[file.fieldName] = fs.createReadStream(file.path);
|
|
|
});
|
|
|
reqParams.formData = Object.assign({}, req.query, req.body, baseParams, reqFiles);
|
|
|
reqOptions.formData = Object.assign(reqParams, baseParams, reqFiles);
|
|
|
} else {
|
|
|
reqParams.body = JSON.stringify(Object.assign({}, req.query, req.body, baseParams));
|
|
|
reqOptions.body = JSON.stringify(Object.assign(reqParams, baseParams));
|
|
|
}
|
|
|
|
|
|
return api.proxy(reqParams).on('error', error => {
|
|
|
return api.proxy(reqOptions).on('error', error => {
|
|
|
next({code: 500, message: error});
|
|
|
}).pipe(res);
|
|
|
}
|
...
|
...
|
|