Merge branch 'guox191-fix468'

This commit is contained in:
xiaofeng.mxf 2019-03-13 22:43:21 +08:00
commit a8c9f590fc
4 changed files with 16 additions and 20 deletions

View File

@ -221,7 +221,7 @@ function getWsReqInfo(wsReq) {
// TODO 如果是windows机器url是不是全路径需要对其过滤取出
const path = wsReq.url || '/';
const isEncript = true && wsReq.connection && wsReq.connection.encrypted;
const isEncript = wsReq.connection && wsReq.connection.encrypted;
/**
* construct the request headers based on original connection,
* but delete the `sec-websocket-*` headers as they are already consumed by AnyProxy

View File

@ -68,10 +68,9 @@ class webInterface extends events.EventEmitter {
customMenu = ''; // userRule._getCustomMenu();
} catch (e) { }
const myAbsAddress = 'http://' + ipAddress + ':' + self.webPort + '/',
staticDir = path.join(__dirname, '../', webBasePath);
const staticDir = path.join(__dirname, '../', webBasePath);
const app = express();
app.use(compress()); //invoke gzip
app.use((req, res, next) => {
res.setHeader('note', 'THIS IS A REQUEST FROM ANYPROXY WEB INTERFACE');
@ -217,35 +216,32 @@ class webInterface extends events.EventEmitter {
//make qr code
app.get('/qr', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
const qr = qrCode.qrcode(4, 'M'),
targetUrl = myAbsAddress;
res.setHeader('Content-Type', 'text/html');
const qr = qrCode.qrcode(4, 'M');
const targetUrl = req.protocol + '://' + req.get('host');
qr.addData(targetUrl);
qr.make();
const qrImageTag = qr.createImgTag(4);
const resDom = '<a href="__url"> __img <br> click or scan qr code to start client </a>'.replace(/__url/, targetUrl).replace(/__img/, qrImageTag);
res.setHeader('Content-Type', 'text/html');
res.end(resDom);
});
app.get('/api/getQrCode', (req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
const qr = qrCode.qrcode(4, 'M'),
targetUrl = myAbsAddress + 'fetchCrtFile';
const qr = qrCode.qrcode(4, 'M');
const targetUrl = req.protocol + '://' + req.get('host') + '/fetchCrtFile';
const isRootCAFileExists = certMgr.isRootCAFileExists();
qr.addData(targetUrl);
qr.make();
const qrImageTag = qr.createImgTag(4);
// resDom = '<a href="__url"> __img <br> click or scan qr code to download rootCA.crt </a>'.replace(/__url/,targetUrl).replace(/__img/,qrImageTag);
// res.setHeader("Content-Type", "text/html");
// res.end(resDom);
const isRootCAFileExists = certMgr.isRootCAFileExists();
res.json({
status: 'success',
url: targetUrl,
isRootCAFileExists,
qrImgDom: qrImageTag
qrImgDom: qr.createImgTag(4)
});
});

View File

@ -102,7 +102,7 @@ class wsServer {
try {
data = JSON.stringify(data);
} catch (e) {
console.error('==> errorr when do broadcast ', e, data);
console.error('==> error when do broadcast ', e, data);
}
}
for (const client of wss.clients) {

View File

@ -67,7 +67,7 @@ function KoaServer() {
this.logWsRequest = function (wsReq) {
const headers = wsReq.headers;
const host = headers.host;
const isEncript = true && wsReq.connection && wsReq.connection.encrypted;
const isEncript = wsReq.connection && wsReq.connection.encrypted;
const protocol = isEncript ? 'wss' : 'ws';
let key = `${protocol}://${host}${wsReq.url}`;
// take proxy data with 'proxy-' + url