Mitm support for windows
This commit is contained in:
Родитель
d570e07f2e
Коммит
b26d2d20c7
|
@ -52,7 +52,9 @@ overriden using command line options:
|
||||||
-e, --expired Use expired cache when npm registry unavailable
|
-e, --expired Use expired cache when npm registry unavailable
|
||||||
-f, --friendly-names Use actual file names instead of hashes in the cache
|
-f, --friendly-names Use actual file names instead of hashes in the cache
|
||||||
-v, --verbose Verbose mode
|
-v, --verbose Verbose mode
|
||||||
--help This help
|
-l, --log-path Log path
|
||||||
|
-m, --internal-port HTTPs port to use for internal proxying "MITM" server (necessary for running on Windows systems)
|
||||||
|
--help This help
|
||||||
|
|
||||||
|
|
||||||
## Why can't I use the built-in npm cache?
|
## Why can't I use the built-in npm cache?
|
||||||
|
|
|
@ -19,7 +19,8 @@ program
|
||||||
.option('-f, --friendly-names', 'Use actual file names instead of hashes in the cache')
|
.option('-f, --friendly-names', 'Use actual file names instead of hashes in the cache')
|
||||||
.option('-v, --verbose', 'Verbose mode')
|
.option('-v, --verbose', 'Verbose mode')
|
||||||
.option('-l, --log-path [path]', 'Log path')
|
.option('-l, --log-path [path]', 'Log path')
|
||||||
.option('-m, --mitmport [port]', 'HTTPs port to use instead of MITM (necessary for running on Windows systems)')
|
.option('-m, --internal-port [port]',
|
||||||
|
'HTTPs port to use for internal proxying "MITM" server (necessary for running on Windows systems)')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
require('../lib/proxy').powerup(program);
|
require('../lib/proxy').powerup(program);
|
||||||
|
|
29
lib/proxy.js
29
lib/proxy.js
|
@ -3,8 +3,9 @@ var http = require('http'),
|
||||||
https = require('https'),
|
https = require('https'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
os = require('os'),
|
os = require('os'),
|
||||||
request = require('request'),
|
|
||||||
url = require('url'),
|
url = require('url'),
|
||||||
|
path = require('path'),
|
||||||
|
request = require('request'),
|
||||||
log4js = require('log4js');
|
log4js = require('log4js');
|
||||||
Cache = require('./cache');
|
Cache = require('./cache');
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||||
|
|
||||||
|
|
||||||
// socket path for system mitm https server
|
// socket path for system mitm https server
|
||||||
var mitmSocketPath = os.tmpdir() + '/mitm.sock';
|
var mitmSocketPath = path.join(os.tmpdir(), 'mitm.sock')
|
||||||
|
|
||||||
|
|
||||||
exports.log = null;
|
exports.log = null;
|
||||||
|
@ -45,19 +46,23 @@ exports.powerup = function(opts) {
|
||||||
log4js.addAppender(log4js.appenders.file(opts.logPath), 'proxy');
|
log4js.addAppender(log4js.appenders.file(opts.logPath), 'proxy');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fake https server, MITM if you want
|
||||||
|
var mitm = https.createServer(options, this.handler);
|
||||||
|
|
||||||
if(!opts.mitmport){
|
// NOTE: for windows platform user has to specify port, because
|
||||||
// make sure there's no previously created socket
|
// windows does not support unix sockets.
|
||||||
if (fs.existsSync(mitmSocketPath))
|
if (process.platform.indexOf('win') === 0) {
|
||||||
fs.unlinkSync(mitmSocketPath);
|
if (!opts.internalPort)
|
||||||
|
throw new Error('For Windows platform you have to specify internal port using `--internal-port` option');
|
||||||
|
|
||||||
|
// Cleanup MITM socket for unix platforms
|
||||||
} else {
|
} else {
|
||||||
// replace mitm socket path with port
|
if (fs.existsSync(mitmSocketPath))
|
||||||
// this is necessary on Windows, otherwise it will not work (MITM not supported)
|
fs.unlinkSync(mitmSocketPath);
|
||||||
mitmSocketPath = opts.mitmport;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fake https server, MITM if you want
|
mitm.listen(opts.internalPort || mitmSocketPath);
|
||||||
https.createServer(options, this.handler).listen(mitmSocketPath);
|
|
||||||
|
|
||||||
// start HTTP server with custom request handler callback function
|
// start HTTP server with custom request handler callback function
|
||||||
var server = http.createServer(this.handler).listen(opts.port, opts.host, function(err) {
|
var server = http.createServer(this.handler).listen(opts.port, opts.host, function(err) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче