http-mock-json-server
Advanced tools
Comparing version
@@ -19,2 +19,6 @@ 'use strict'; | ||
var _https = require('https'); | ||
var _https2 = _interopRequireDefault(_https); | ||
var _mime = require('mime'); | ||
@@ -109,2 +113,41 @@ | ||
var proxyToSourceServer = function proxyToSourceServer(request, response, config, callback) { | ||
//let urlObject = url.parse(request.url); | ||
//if(urlObject.protocol == "https") { | ||
proxyHttp(request, response, config, callback); | ||
// } else if(urlObject.protocol == "http") { | ||
// proxyHttps(request, response, config, callback); | ||
// } else { | ||
// callback(null, [new Error(`protocol ${urlObject.protocol} is not supported`)]); | ||
// } | ||
}; | ||
// const proxyHttps = function (request, response, config, callback) { | ||
// let options = { | ||
// host: config.ip, | ||
// port: config.port || "443", | ||
// method: request.method, | ||
// path: request.url, | ||
// headers: request.headers | ||
// }; | ||
// let body = ''; | ||
// let req = https.request(opt, function (res) { | ||
// res.pipe(response); | ||
// response.writeHeader(res.statusCode, res.headers); | ||
// console.log("Got response: " + res.statusCode); | ||
// res.on('data', function (d) { | ||
// body += d; | ||
// }).on('end', function () { | ||
// callback(body, null, true); | ||
// }); | ||
// }).on('error', function (e) { | ||
// callback(null, [e]); | ||
// }) | ||
// req.end(); | ||
// } | ||
var proxyHttp = function proxyHttp(request, response, config, callback) { | ||
var opt = { | ||
@@ -132,3 +175,8 @@ host: config.ip, | ||
}); | ||
req.end(); | ||
if (/POST|PUT/i.test(request.method)) { | ||
request.pipe(req); | ||
} else { | ||
req.end(); | ||
} | ||
}; | ||
@@ -161,5 +209,5 @@ | ||
console.error(_chalk2.default.bold.white.bgRed(' ERROR ')); | ||
err.some(function (_err) { | ||
console.error(_err); | ||
}); | ||
//err.some(function (_err) { | ||
console.error(err); | ||
//}); | ||
@@ -166,0 +214,0 @@ if (fileData) { |
@@ -23,4 +23,2 @@ 'use strict'; | ||
console.log(process.cwd()); | ||
_commander2.default.version(pkg.version).option('-p, --port [value]', '监听端口').description('开启 http mock server').parse(process.argv); | ||
@@ -27,0 +25,0 @@ |
{ | ||
"name": "http-mock-json-server", | ||
"version": "0.1.0-beta1", | ||
"version": "0.1.0-beta2", | ||
"description": "Create the HTTP server is used to generate mock json using mockjs", | ||
@@ -44,2 +44,3 @@ "main": "dist/mock.js", | ||
"deep-assign": "^2.0.0", | ||
"http-proxy": "^1.14.0", | ||
"mime": "^1.3.4", | ||
@@ -46,0 +47,0 @@ "minimatch": "^0.2.14", |
@@ -50,5 +50,5 @@ # http-mock-json-server | ||
``` | ||
host:需要代理的域名 | ||
ip:需要代理的域名的ip | ||
port:需要代理的域名的端口 | ||
host:需要代理的域名,非必填 | ||
ip:需要代理的域名的ip,非必填,如果不填,相当于放弃proxy到源服务器。 | ||
port:需要代理的域名的端口,非必填 | ||
mock:请求路径和模板的匹配关系。 | ||
@@ -55,0 +55,0 @@ pathname:请求路径 |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
223162
2.85%18
5.88%1817
2.14%10
11.11%4
33.33%+ Added
+ Added
+ Added
+ Added
+ Added