Sitelet https://github.com/alibaba/anyproxy/commit/a8c9f590fcbd8e2fdea457688b8f13b1583b96f7
Skip to content

Commit a8c9f59

Browse files
author
xiaofeng.mxf
committed
Merge branch 'guox191-fix468'
2 parents d44ce7f + 59e0585 commit a8c9f59

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

‎lib/requestHandler.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ function getWsReqInfo(wsReq) {
221221
// TODO 如果是windows机器,url是不是全路径?需要对其过滤,取出
222222
const path = wsReq.url || '/';
223223

224-
const isEncript = true && wsReq.connection && wsReq.connection.encrypted;
224+
const isEncript = wsReq.connection && wsReq.connection.encrypted;
225225
/**
226226
* construct the request headers based on original connection,
227227
* but delete the `sec-websocket-*` headers as they are already consumed by AnyProxy

‎lib/webInterface.js‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class webInterface extends events.EventEmitter {
5656
*/
5757
getServer() {
5858
const self = this;
59-
const recorder = self.recorder;
59+
const recorder = self.recorder;
6060
const ipAddress = ip.address(),
6161
// userRule = proxyInstance.proxyRule,
6262
webBasePath = 'web';
@@ -68,10 +68,9 @@ class webInterface extends events.EventEmitter {
6868
customMenu = ''; // userRule._getCustomMenu();
6969
} catch (e) { }
7070

71-
const myAbsAddress = 'http://' + ipAddress + ':' + self.webPort + '/',
72-
staticDir = path.join(__dirname, '../', webBasePath);
73-
71+
const staticDir = path.join(__dirname, '../', webBasePath);
7472
const app = express();
73+
7574
app.use(compress()); //invoke gzip
7675
app.use((req, res, next) => {
7776
res.setHeader('note', 'THIS IS A REQUEST FROM ANYPROXY WEB INTERFACE');
@@ -217,35 +216,32 @@ class webInterface extends events.EventEmitter {
217216
//make qr code
218217
app.get('/qr', (req, res) => {
219218
res.setHeader('Access-Control-Allow-Origin', '*');
220-
const qr = qrCode.qrcode(4, 'M'),
221-
targetUrl = myAbsAddress;
219+
res.setHeader('Content-Type', 'text/html');
220+
221+
const qr = qrCode.qrcode(4, 'M');
222+
const targetUrl = req.protocol + '://' + req.get('host');
222223
qr.addData(targetUrl);
223224
qr.make();
224225
const qrImageTag = qr.createImgTag(4);
225226
const resDom = '<a href="__url"> __img <br> click or scan qr code to start client </a>'.replace(/__url/, targetUrl).replace(/__img/, qrImageTag);
226-
res.setHeader('Content-Type', 'text/html');
227227
res.end(resDom);
228228
});
229229

230230
app.get('/api/getQrCode', (req, res) => {
231231
res.setHeader('Access-Control-Allow-Origin', '*');
232-
const qr = qrCode.qrcode(4, 'M'),
233-
targetUrl = myAbsAddress + 'fetchCrtFile';
232+
233+
const qr = qrCode.qrcode(4, 'M');
234+
const targetUrl = req.protocol + '://' + req.get('host') + '/fetchCrtFile';
235+
const isRootCAFileExists = certMgr.isRootCAFileExists();
234236

235237
qr.addData(targetUrl);
236238
qr.make();
237-
const qrImageTag = qr.createImgTag(4);
238239

239-
// resDom = '<a href="__url"> __img <br> click or scan qr code to download rootCA.crt </a>'.replace(/__url/,targetUrl).replace(/__img/,qrImageTag);
240-
// res.setHeader("Content-Type", "text/html");
241-
// res.end(resDom);
242-
243-
const isRootCAFileExists = certMgr.isRootCAFileExists();
244240
res.json({
245241
status: 'success',
246242
url: targetUrl,
247243
isRootCAFileExists,
248-
qrImgDom: qrImageTag
244+
qrImgDom: qr.createImgTag(4)
249245
});
250246
});
251247

‎lib/wsServer.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class wsServer {
7272
clientTracking: true,
7373
});
7474
resolve();
75-
75+
7676
// the queue of the messages to be delivered
7777
let messageQueue = [];
7878
// the flat to indicate wheter to broadcast the record
@@ -102,7 +102,7 @@ class wsServer {
102102
try {
103103
data = JSON.stringify(data);
104104
} catch (e) {
105-
console.error('==> errorr when do broadcast ', e, data);
105+
console.error('==> error when do broadcast ', e, data);
106106
}
107107
}
108108
for (const client of wss.clients) {

‎test/server/server.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function KoaServer() {
6767
this.logWsRequest = function (wsReq) {
6868
const headers = wsReq.headers;
6969
const host = headers.host;
70-
const isEncript = true && wsReq.connection && wsReq.connection.encrypted;
70+
const isEncript = wsReq.connection && wsReq.connection.encrypted;
7171
const protocol = isEncript ? 'wss' : 'ws';
7272
let key = `${protocol}://${host}${wsReq.url}`;
7373
// take proxy data with 'proxy-' + url

0 commit comments

Comments
 (0)