Comparing version 2.0.5 to 2.0.6-beta
16
index.js
@@ -150,3 +150,3 @@ 'use strict'; | ||
let headers = u.headers || service.headers; | ||
let log = app && app.getLog() || console; | ||
let log = (app && app.log) || console; | ||
let file = u.file || false; | ||
@@ -160,3 +160,2 @@ let useQuerystringInDelete = !_.isNil(service.useQuerystringInDelete) ? !!service.useQuerystringInDelete : | ||
let beforeResponse = u.beforeResponse; | ||
let statusCode = u.return; | ||
@@ -182,3 +181,2 @@ return { | ||
defaultErrorCode, | ||
statusCode, | ||
beforeRequest, | ||
@@ -196,3 +194,2 @@ beforeResponse | ||
let file = u.file; | ||
let statusCode = u.statusCode; | ||
if (!clients[client]) { | ||
@@ -227,11 +224,4 @@ throw new Error(`[hc-proxy] there is no 'client' called:${client} at hc-proxy config ${serviceName}`); | ||
} | ||
if (statusCode) { | ||
router[m.toLowerCase()](router, (req, res, next) => { | ||
res.statusCode = statusCode; | ||
res.end(); | ||
}); | ||
} else { | ||
// 支持 framework5.0, 需要使用 isWrapper 来辨认是否是 callback 回调 | ||
router[m.toLowerCase()](route, clients[client](u, proxyHeaders), true); | ||
} | ||
// 支持 framework5.0, 需要使用 isWrapper 来辨认是否是 callback 回调 | ||
router[m.toLowerCase()](route, clients[client](u, proxyHeaders), true); | ||
}); | ||
@@ -238,0 +228,0 @@ }); |
'use strict'; | ||
const pathToRegexp = require('path-to-regexp'); | ||
const qs = require('qs'); | ||
const url = require('url'); | ||
const qs = require('qs'); | ||
const formstream = require('formstream'); | ||
const utils = require('./utils'); | ||
const pathToRegexp = require('path-to-regexp'); | ||
const ServiceClient = require('hc-service-client').ServiceClient; | ||
const utils = require('./utils'); | ||
module.exports = function (u, proxyHeaders) { | ||
@@ -18,3 +19,2 @@ let endpoint = u.endpoint; | ||
let accessKeySecret = u.accessKeySecret; | ||
let headers = u.headers; | ||
let _isIgnoreRequestFrom = service._isIgnoreRequestFrom; | ||
@@ -79,8 +79,17 @@ let log = u.log || console; | ||
// upload file | ||
if (u.file && req.files && req.files.length) { | ||
if (u.file || (req.files && req.files.length)) { | ||
const form = formstream(); | ||
const data = options.data || {}; | ||
Object.keys(data).forEach(k => { | ||
if(!data[k]) { | ||
return; | ||
} | ||
if(data[k].constructor === Object) { | ||
form.field(k, JSON.stringify(data[k])); | ||
} | ||
form.field(k, data[k]); | ||
}); | ||
options.data = null; | ||
@@ -98,2 +107,3 @@ req.files.forEach(f => { | ||
} | ||
if ('DELETE' === req.method && u.useQuerystringInDelete) { | ||
@@ -100,0 +110,0 @@ options.dataAsQueryString = true; |
{ | ||
"name": "hc-proxy", | ||
"version": "2.0.5", | ||
"version": "2.0.6-beta", | ||
"description": "honeycomb api proxy express middleware.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "make test" | ||
"test": "make test", | ||
"cover": "make cover" | ||
}, | ||
@@ -13,3 +14,3 @@ "dependencies": { | ||
"hc-service-client": "^1.0.0", | ||
"lodash": "4.15.0", | ||
"lodash": "4.17.19", | ||
"multer": "1.3.0", | ||
@@ -30,4 +31,5 @@ "path-to-regexp": "1.6.0", | ||
"mocha": "^4.0.1", | ||
"nyc": "^15.1.0", | ||
"supertest": "^3.0.0" | ||
} | ||
} |
@@ -120,6 +120,2 @@ # hc-proxy | ||
{ | ||
path: '/api/404', | ||
return: 404 | ||
}, | ||
{ | ||
path: '/api/upload', | ||
@@ -126,0 +122,0 @@ file: true |
'use strict'; | ||
const errorProxy = require('./server/error_proxy'); | ||
const httpServer = require('./server/http_server'); | ||
const proxyServer = require('./server/proxy_server'); | ||
const errorProxy = require('./server/error_proxy'); | ||
const request = require('supertest'); | ||
const http = require('http'); | ||
const assert = require('assert'); | ||
const request = require('supertest'); | ||
const debug = require('debug')('hc-proxy-test'); | ||
@@ -309,2 +310,17 @@ | ||
it('upload with or without file still with header form', (done) => { | ||
request(proxyInstance) | ||
.post('/api/proxy/app_client/common/resource/add/without') | ||
.field('platform', 'ODPS') | ||
.field('sourceType', 'JAR') | ||
.field('name', 'hello.jar') | ||
.field('description', 'hc-proxy test') | ||
.field('scopeId', 'dtboost') | ||
.expect(200).end(function (err, res) { | ||
const d = JSON.parse(res.text); | ||
assert(d['content-type'].includes('form-data')); | ||
done(); | ||
}); | ||
}); | ||
after(() => { | ||
@@ -311,0 +327,0 @@ proxyInstance.close(); |
'use strict'; | ||
const http = require('http'); | ||
const stream = require('stream'); | ||
const express = require('express'); | ||
@@ -30,4 +30,13 @@ const app = express(); | ||
method: 'POST', | ||
file: true | ||
} | ||
file: true, | ||
}, | ||
{ | ||
path: '/common/resource/add/without', | ||
method: 'POST', | ||
file: true, | ||
beforeResponse: (req) => { | ||
const response = new stream.PassThrough(); | ||
return response.end(Buffer.from(JSON.stringify(req.headers))); | ||
} | ||
} | ||
] | ||
@@ -118,3 +127,5 @@ }, | ||
processor(req, (err, response) => { | ||
response.pipe(res); | ||
if(response.pipe) { | ||
return response.pipe(res); | ||
} | ||
}); | ||
@@ -160,2 +171,3 @@ }); | ||
}; | ||
proxyInstance.mount(mockRouter, { | ||
@@ -162,0 +174,0 @@ server, |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
52560
15
1190
6
4
2
327
+ Addedlodash@4.17.19(transitive)
- Removedlodash@4.15.0(transitive)
Updatedlodash@4.17.19