mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-10 06:48:26 +00:00
add stop btn to web interface
This commit is contained in:
parent
4bffdf8224
commit
c5624a3c6b
@ -1,8 +1,17 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
shouldUseLocalResponse : function(req,reqBody){
|
shouldUseLocalResponse : function(req,reqBody){
|
||||||
|
//intercept all options request
|
||||||
|
if(req.method == "OPTIONS"){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
dealLocalResponse : function(req,reqBody,callback){
|
dealLocalResponse : function(req,reqBody,callback){
|
||||||
|
if(req.method == "OPTIONS"){
|
||||||
|
callback(200,mergeCORSHeader(req.headers),"");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
replaceRequestProtocol:function(req,protocol){
|
replaceRequestProtocol:function(req,protocol){
|
||||||
@ -18,6 +27,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
replaceResponseHeader: function(req,res,header){
|
replaceResponseHeader: function(req,res,header){
|
||||||
|
return mergeCORSHeader(req.headers, header);
|
||||||
},
|
},
|
||||||
|
|
||||||
replaceServerResData: function(req,res,serverResData){
|
replaceServerResData: function(req,res,serverResData){
|
||||||
@ -28,4 +38,20 @@ module.exports = {
|
|||||||
|
|
||||||
shouldInterceptHttpsReq :function(req){
|
shouldInterceptHttpsReq :function(req){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function mergeCORSHeader(reqHeader,originHeader){
|
||||||
|
var targetObj = originHeader || {};
|
||||||
|
|
||||||
|
delete targetObj["Access-Control-Allow-Credentials"];
|
||||||
|
delete targetObj["Access-Control-Allow-Origin"];
|
||||||
|
delete targetObj["Access-Control-Allow-Methods"];
|
||||||
|
delete targetObj["Access-Control-Allow-Headers"];
|
||||||
|
|
||||||
|
targetObj["access-control-allow-credentials"] = "true";
|
||||||
|
targetObj["access-control-allow-origin"] = reqHeader['origin'] || "-___-||";
|
||||||
|
targetObj["access-control-allow-methods"] = "GET, POST, PUT";
|
||||||
|
targetObj["access-control-allow-headers"] = reqHeader['access-control-request-headers'] || "-___-||";
|
||||||
|
|
||||||
|
return targetObj;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "anyproxy",
|
"name": "anyproxy",
|
||||||
"version": "2.1.0",
|
"version": "2.1.1",
|
||||||
"description": "a charles/fiddler like proxy written in NodeJs, which can handle HTTPS requests and CROS perfectly.",
|
"description": "a charles/fiddler like proxy written in NodeJs, which can handle HTTPS requests and CROS perfectly.",
|
||||||
"main": "proxy.js",
|
"main": "proxy.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
4
proxy.js
4
proxy.js
@ -144,9 +144,7 @@ function startWebServer(port){
|
|||||||
|
|
||||||
//web socket interface
|
//web socket interface
|
||||||
var wss = new WebSocketServer({port: DEFAULT_WEBSOCKET_PORT});
|
var wss = new WebSocketServer({port: DEFAULT_WEBSOCKET_PORT});
|
||||||
wss.on("connection",function(ws){
|
wss.on("connection",function(ws){});
|
||||||
console.log("wss connection");
|
|
||||||
});
|
|
||||||
wss.broadcast = function(data) {
|
wss.broadcast = function(data) {
|
||||||
for(var i in this.clients){
|
for(var i in this.clients){
|
||||||
this.clients[i].send(data);
|
this.clients[i].send(data);
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
margin: 0 5px;
|
margin: 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.topHead .btn_disable{
|
||||||
|
color: #777;
|
||||||
|
}
|
||||||
|
|
||||||
.mainTableWrapper{
|
.mainTableWrapper{
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
<div class="topHead">
|
<div class="topHead">
|
||||||
<h1>Anyproxy</h1>
|
<h1>Anyproxy</h1>
|
||||||
<a href="#" class="J_clearBtn"><span class="topBtn">Clear Logs(Ctrl+X)</span></a>
|
<a href="#" class="J_clearBtn"><span class="topBtn">Clear Logs(Ctrl+X)</span></a>
|
||||||
|
<a href="#" class="J_statusBtn"><span class="topBtn">Stop</span></a>
|
||||||
|
<a href="#" class="J_statusBtn btn_disable"><span class="topBtn">Resume</span></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mainTableWrapper J_mainTable">
|
<div class="mainTableWrapper J_mainTable">
|
||||||
|
21
web/page.js
21
web/page.js
@ -13,7 +13,6 @@ seajs.use(['$','Underscore' ,'Backbone'], function($, _, Backbone) {
|
|||||||
$(function(){
|
$(function(){
|
||||||
|
|
||||||
//record detail
|
//record detail
|
||||||
//backbone太麻烦了,这里手写拉倒..
|
|
||||||
var DetailView = function(){
|
var DetailView = function(){
|
||||||
var self = this,
|
var self = this,
|
||||||
$detailEl = $(".J_recordDetailOverlay"),
|
$detailEl = $(".J_recordDetailOverlay"),
|
||||||
@ -153,6 +152,25 @@ seajs.use(['$','Underscore' ,'Backbone'], function($, _, Backbone) {
|
|||||||
recList.reset();
|
recList.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pause btn
|
||||||
|
var ifPause = false;
|
||||||
|
(function(){
|
||||||
|
var statusBtn = $(".J_statusBtn");
|
||||||
|
statusBtn.on("click",function(e){
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
$(".J_statusBtn").removeClass("btn_disable");
|
||||||
|
$(this).addClass("btn_disable");
|
||||||
|
|
||||||
|
if(/stop/i.test($(this).html()) ){
|
||||||
|
ifPause = true;
|
||||||
|
}else{
|
||||||
|
ifPause = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
//data via web socket
|
//data via web socket
|
||||||
if(!WebSocket){
|
if(!WebSocket){
|
||||||
alert("WebSocket is required. Please use a modern browser.");
|
alert("WebSocket is required. Please use a modern browser.");
|
||||||
@ -162,6 +180,7 @@ seajs.use(['$','Underscore' ,'Backbone'], function($, _, Backbone) {
|
|||||||
dataSocket.onopen = function(){}
|
dataSocket.onopen = function(){}
|
||||||
|
|
||||||
dataSocket.onmessage = function(event){
|
dataSocket.onmessage = function(event){
|
||||||
|
if(ifPause) return;
|
||||||
var data = JSON.parse(event.data);
|
var data = JSON.parse(event.data);
|
||||||
|
|
||||||
var reqDate = new Date(data.startTime);
|
var reqDate = new Date(data.startTime);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user