Showing
1 changed file
with
9 additions
and
5 deletions
@@ -55,7 +55,7 @@ module.exports = (req, res, next) => { | @@ -55,7 +55,7 @@ module.exports = (req, res, next) => { | ||
55 | platform_id: config.platform, | 55 | platform_id: config.platform, |
56 | userId: req.user.uid | 56 | userId: req.user.uid |
57 | }; | 57 | }; |
58 | - let reqParams = Object.assign({ | 58 | + let reqOptions = Object.assign({ |
59 | url: apiUrl, | 59 | url: apiUrl, |
60 | method: req.method.toLowerCase(), | 60 | method: req.method.toLowerCase(), |
61 | headers: { | 61 | headers: { |
@@ -64,26 +64,30 @@ module.exports = (req, res, next) => { | @@ -64,26 +64,30 @@ module.exports = (req, res, next) => { | ||
64 | 'Content-Type': 'application/json' | 64 | 'Content-Type': 'application/json' |
65 | } | 65 | } |
66 | }); | 66 | }); |
67 | + let reqParams = Object.assign({}, req.query, req.body); | ||
67 | let files = req.files && req.files.file || []; | 68 | let files = req.files && req.files.file || []; |
68 | 69 | ||
69 | if (!_.isArray(files)) { | 70 | if (!_.isArray(files)) { |
70 | files = [files]; | 71 | files = [files]; |
71 | } | 72 | } |
73 | + if (reqParams.platform_id) { | ||
74 | + delete baseParams.platform_id; | ||
75 | + } | ||
72 | 76 | ||
73 | if (req.method.toLowerCase() === 'get') { | 77 | if (req.method.toLowerCase() === 'get') { |
74 | - reqParams.qs = Object.assign({}, req.query, req.body, baseParams); | 78 | + reqOptions.qs = Object.assign(reqParams, baseParams); |
75 | } else if (files.length) { | 79 | } else if (files.length) { |
76 | let reqFiles = {}; | 80 | let reqFiles = {}; |
77 | 81 | ||
78 | _.each(files, file => { | 82 | _.each(files, file => { |
79 | reqFiles[file.fieldName] = fs.createReadStream(file.path); | 83 | reqFiles[file.fieldName] = fs.createReadStream(file.path); |
80 | }); | 84 | }); |
81 | - reqParams.formData = Object.assign({}, req.query, req.body, baseParams, reqFiles); | 85 | + reqOptions.formData = Object.assign(reqParams, baseParams, reqFiles); |
82 | } else { | 86 | } else { |
83 | - reqParams.body = JSON.stringify(Object.assign({}, req.query, req.body, baseParams)); | 87 | + reqOptions.body = JSON.stringify(Object.assign(reqParams, baseParams)); |
84 | } | 88 | } |
85 | 89 | ||
86 | - return api.proxy(reqParams).on('error', error => { | 90 | + return api.proxy(reqOptions).on('error', error => { |
87 | next({code: 500, message: error}); | 91 | next({code: 500, message: error}); |
88 | }).pipe(res); | 92 | }).pipe(res); |
89 | } | 93 | } |
-
Please register or login to post a comment