mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-04-24 06:21:26 +00:00
fix #468
This commit is contained in:
parent
d44ce7fd08
commit
59e05850fa
@ -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
|
||||
|
@ -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)
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user