diff --git a/README.md b/README.md index d2a7c4f..04f1566 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ Mac 下 第三步:设置手机的HTTP代理,代理IP地址设置为PC的IP地址,端口为`spy-debugger`的启动端口(默认端口:9888)。 +第四步:手机浏览器访问:http://spydebugger.com/cert 安装证书。 + 第四步:用手机浏览器访问你要调试的页面即可。 ## 自定义选项 diff --git a/lib/config/config.js b/lib/config/config.js index 5303433..518d193 100644 --- a/lib/config/config.js +++ b/lib/config/config.js @@ -1,6 +1,8 @@ 'use strict'; var SPY_WEINRE_DOMAIN = 'spyweinrefortest.com'; +var SPY_DEBUGGER_DOMAIN = 'spydebugger.com'; var config = exports; -config.SPY_WEINRE_DOMAIN = SPY_WEINRE_DOMAIN; \ No newline at end of file +config.SPY_WEINRE_DOMAIN = SPY_WEINRE_DOMAIN; +config.SPY_DEBUGGER_DOMAIN = SPY_DEBUGGER_DOMAIN; \ No newline at end of file diff --git a/lib/proxy/spyProxy.js b/lib/proxy/spyProxy.js index 308c6fe..699acf2 100644 --- a/lib/proxy/spyProxy.js +++ b/lib/proxy/spyProxy.js @@ -7,6 +7,8 @@ var zlib = require('zlib'); var through = require('through2'); var config = require('../config/config'); var htmlUtil = require('../util/htmlUtil'); +var path = require('path'); +var fs = require('fs'); module.exports = { createProxy: function createProxy(_ref) { @@ -31,6 +33,21 @@ module.exports = { } }, requestInterceptor: function requestInterceptor(rOptions, req, res, ssl, next) { + + if (rOptions.hostname === config.SPY_DEBUGGER_DOMAIN && rOptions.path === '/cert') { + var userHome = process.env.HOME || process.env.USERPROFILE; + var certPath = path.resolve(userHome, './node-mitmproxy/node-mitmproxy.ca.crt'); + try { + var fileString = fs.readFileSync(certPath); + res.setHeader('Content-Type', 'application/x-x509-ca-cert'); + res.end(fileString.toString()); + } catch (e) { + console.log(e); + res.end('please create certificate first!!'); + } + next(); + return; + } if (rOptions.hostname === config.SPY_WEINRE_DOMAIN) { rOptions.protocol = 'http:'; rOptions.hostname = '127.0.0.1'; diff --git a/package.json b/package.json index 6b60c52..a675114 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spy-debugger", - "version": "2.0.4", + "version": "2.0.5", "description": "web page one-stop remote network debugger", "main": "lib/index.js", "scripts": { diff --git a/src/config/config.js b/src/config/config.js index 3295716..dc39b43 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -1,4 +1,6 @@ const SPY_WEINRE_DOMAIN = 'spyweinrefortest.com'; +const SPY_DEBUGGER_DOMAIN = 'spydebugger.com'; var config = exports; config.SPY_WEINRE_DOMAIN = SPY_WEINRE_DOMAIN; +config.SPY_DEBUGGER_DOMAIN = SPY_DEBUGGER_DOMAIN; diff --git a/src/proxy/spyProxy.js b/src/proxy/spyProxy.js index 50cd8c7..6f5add1 100644 --- a/src/proxy/spyProxy.js +++ b/src/proxy/spyProxy.js @@ -5,6 +5,8 @@ const zlib = require('zlib'); const through = require('through2'); const config = require('../config/config'); const htmlUtil = require('../util/htmlUtil'); +const path = require('path'); +const fs = require('fs'); module.exports = { @@ -29,6 +31,21 @@ module.exports = { } }, requestInterceptor: (rOptions, req, res, ssl, next) => { + + if (rOptions.hostname === config.SPY_DEBUGGER_DOMAIN && rOptions.path === '/cert'){ + var userHome = process.env.HOME || process.env.USERPROFILE; + var certPath = path.resolve(userHome, './node-mitmproxy/node-mitmproxy.ca.crt'); + try { + var fileString = fs.readFileSync(certPath); + res.setHeader('Content-Type', 'application/x-x509-ca-cert'); + res.end(fileString.toString()); + } catch (e) { + console.log(e); + res.end('please create certificate first!!'); + } + next(); + return; + } if (rOptions.hostname === config.SPY_WEINRE_DOMAIN) { rOptions.protocol = 'http:' rOptions.hostname = '127.0.0.1'