흐음. 정규표현식은 매번 써도 모르겠다...

아무튼 내용을 없는걸로 치환하면 될 듯

 

[링크 : https://soooprmx.com/archives/7718]

[링크 : https://stackoverflow.com/.../regular-expression-to-remove-one-parameter-from-query-string]

[링크 : https://stackoverflow.com/.../how-do-you-match-multiple-regex-patterns-for-a-single-line-of-text-in-java]

 

 

'Programming > regexp(정규표현식)' 카테고리의 다른 글

정규 표현식.. 반복  (0) 2019.09.17
정규표현식 n개 이상  (0) 2019.08.30
regexp non-capturing group  (0) 2019.08.22
정규표현식 - regular expression  (0) 2009.01.18
Posted by 구차니
Programming/node.js2019. 4. 2. 16:32

NodeMITMProxyCA 라는녀석이 생성되서 찾아보니 아래의 경로에 생성을 한다.

흐음.. 서비스 용으로 만들려면 이 이름을 어떻게 바꿔치워야 겠네? ㅠㅠ

./.http-mitm-proxy/certs/ca.pem
./.http-mitm-proxy/keys/ca.private.key
./.http-mitm-proxy/keys/ca.public.key

[링크 : https://github.com/greim/hoxy]

[링크 : https://stackoverflow.com/questions/10085082/node-http-proxy-ssl-transparent]

[링크 : https://github.com/TotallyInformation/node-proxy-https-example/blob/master/proxy.js]

[링크 : https://www.npmjs.com/package/http-mitm-proxy]

 

 

아래는 span 에 들어있는 내용을 죄다 Pwned로 바꿔치기 하는 기본 예제를 변형한 녀석

 

var Proxy = require('http-mitm-proxy');
var proxy = Proxy();
var path = require('path');

proxy.use(Proxy.wildcard);

proxy.onError(function(ctx, err) {
  console.error('proxy error:', err);
});

proxy.onRequest(function(ctx, callback) {
//  if (ctx.clientToProxyRequest.headers.host == 'www.google.com'
//    && ctx.clientToProxyRequest.url.indexOf('/search') == 0
//    )
 {
    ctx.use(Proxy.gunzip);

    ctx.onResponseData(function(ctx, chunk, callback) {
//      chunk = new Buffer(chunk.toString().replace(/<h3.*?<\/h3>/g, '<h3>Pwned!</h3>'));
        console.log(chunk.toString());
      chunk = new Buffer(chunk.toString().replace(/<span.*?<\/span>/g, '<span>Pwned!</span>'));
      return callback(null, chunk);
    });
  }
  return callback();
});

proxy.onRequestData(function(ctx, chunk, callback) {
  console.log('REQUEST DATA:', chunk.toString());
  return callback(null, chunk);
});

/*
proxy.onCertificateRequired = function(hostname, callback) {
  return callback(null, {
    keyFile: path.resolve('key.pem'),
    certFile: path.resolve('cert.pem'),
    hosts: ["*"]
  });
};
*/
proxy.listen({port: 8080});

 

사용자가 생성한 인증서를 이용하여 서비스하기

[링크 : http://blog.saltfactory.net/implements-nodejs-based-https-server/]

var Proxy = require('http-mitm-proxy');
var proxy = Proxy();
var path = require('path');

proxy.use(Proxy.wildcard);

proxy.onError(function(ctx, err) {
  console.error('proxy error:', err);
});

proxy.onRequest(function(ctx, callback) {
 {
    ctx.use(Proxy.gunzip);

    ctx.onResponseData(function(ctx, chunk, callback) {
      chunk = new Buffer(chunk.toString().replace(/<span.*?<\/span>/g, '<span>Pwned!</span>'));
      return callback(null, chunk);
    });
  }
  return callback();
});

proxy.onCertificateRequired = function(hostname, callback) {
  return callback(null, {
    keyFile: path.resolve('key.pem'),
    certFile: path.resolve('cert.pem'),
    hosts: ["*.mydomain.com"]
  });
};
proxy.listen({port: 8080});

[링크 : https://github.com/horaci/node-mitm-proxy]

[링크 : https://www.npmjs.com/package/mitm-proxy]

Posted by 구차니
Programming/node.js2019. 4. 1. 10:26

http proxy는 어떻게 보면 특수한 용도의 http 서버일 뿐인데..

http.agent를 써야 하냐 말아야 하냐.. 헷갈리네

 

http는 agent 없어도 proxy 설정하면 받아들이긴 하는데..

https는 http.agent를 통해 socket으로 돌려주는 편이라 어떻게 해야 하지?

 

[링크 : https://stackoverflow.com/questions/20351637/how-to-create-a-simple-http-proxy-in-node-js]

[링크 : https://nodejs.org/api/http.html]

[링크 : https://nodejs.org/api/http.html#http_request_end_data_encoding_callback]

Posted by 구차니
Programming/web 관련2019. 3. 28. 13:07

지금와서 찾아보니 static으로 만 썼구나..

그래도 relative나 absolute는 레이아웃이 붕 뜨는 바람에 나중에 손대기 너무 번거로운데..

 

[링크 : https://www.zerocho.com/category/CSS/post/5864f3b59f1dc000182d3ea1]

[링크 : http://ko.learnlayout.com/position.html]

[링크 : https://aboooks.tistory.com/82]

'Programming > web 관련' 카테고리의 다른 글

web framework  (0) 2019.06.05
ECDHE?  (0) 2019.04.26
webpack  (0) 2019.02.20
ajax bearer token header  (0) 2019.02.07
webGL vs SVG  (0) 2019.01.07
Posted by 구차니
Programming/node.js2019. 3. 27. 18:05

JSON.stringify() 를 하면 위와 같은 에러를 내면서 죽길래

해결책을 찾는데 circular-json 이라는 다른 패키지를 깔아서 써야 한다.

 

[링크 : https://zetawiki.com/wiki/TypeError:_Converting_circular_structure_to_JSON]

[링크 : https://zetawiki.com/wiki/Npm_circular-json]

 

진짜인진 모르겠지만 객체 내에 순환참조가 있음 그렇게 죽는다고..

[링크 : https://ohgyun.com/399]

'Programming > node.js' 카테고리의 다른 글

node.js mitm proxy (for https)  (0) 2019.04.02
proxy http node.js  (0) 2019.04.01
https proxy using node.js  (0) 2019.03.27
node.js unit test  (0) 2019.03.25
node.js http cache proxy  (0) 2019.03.20
Posted by 구차니
Programming/node.js2019. 3. 27. 17:38

stack의 것은.. 되긴 하는데 단순하게(?) https의 경우 소켓을 통해 바로 연결되는 구조로 되어있다.

http나 https 확실히 무언가 한번 걸린다는 느낌이 드는 딜레이는 어쩔수 없을려나?

 

아무튼 내가 원한건.. 얘가 아니라 직접 URL을 잡아낼수 있어야 하는 녀석... ㅠㅠ

 

// Install npm dependencies first
// npm init
// npm install --save url@0.10.3
// npm install --save http-proxy@1.11.1

var httpProxy = require("http-proxy");
var http = require("http");
var url = require("url");
var net = require('net');

var server = http.createServer(function (req, res) {
var urlObj = url.parse(req.url);
var target = urlObj.protocol + "//" + urlObj.host;

console.log("Proxy HTTP request for:", target);

var proxy = httpProxy.createProxyServer({});
proxy.on("error", function (err, req, res) {
console.log("proxy error", err);
res.end();
});

proxy.web(req, res, {target: target});
}).listen(8080); //this is the port your clients will connect to

var regex_hostport = /^([^:]+)(:([0-9]+))?$/;

var getHostPortFromString = function (hostString, defaultPort) {
var host = hostString;
var port = defaultPort;

var result = regex_hostport.exec(hostString);
if (result != null) {
host = result[1];
if (result[2] != null) {
port = result[3];
}
}

return ( [host, port] );
};

server.addListener('connect', function (req, socket, bodyhead) {
var hostPort = getHostPortFromString(req.url, 443);
var hostDomain = hostPort[0];
var port = parseInt(hostPort[1]);
console.log("Proxying HTTPS request for:", hostDomain, port);

var proxySocket = new net.Socket();
proxySocket.connect(port, hostDomain, function () {
proxySocket.write(bodyhead);
socket.write("HTTP/" + req.httpVersion + " 200 Connection established\r\n\r\n");
}
);

proxySocket.on('data', function (chunk) {
socket.write(chunk);
});

proxySocket.on('end', function () {
socket.end();
});

proxySocket.on('error', function () {
socket.write("HTTP/" + req.httpVersion + " 500 Connection error\r\n\r\n");
socket.end();
});

socket.on('data', function (chunk) {
proxySocket.write(chunk);
});

socket.on('end', function () {
proxySocket.end();
});

socket.on('error', function () {
proxySocket.end();
});

});


[링크 : 
https://stackoverflow.com/questions/8165570/https-proxy-server-in-node-js/32104777]

[링크 : https://www.npmjs.com/package/httpp-proxy]

 

이거랑 위에꺼랑 어떻게 믹스하지? ㅠㅠ

[링크 : http://blog.saltfactory.net/implements-nodejs-based-https-server/]

 

+

2019.04.02

취향대로 좀 정리한 버전

var http = require('http');
var httpProxy = require('http-proxy');
var url = require('url');
var net = require('net');

var server = http.createServer(onReq);
server.addListener('connect', onConn);
server.listen(8080);

function onReq(req, res)
{
        var urlObj = url.parse(req.url);
        var target = urlObj.protocol + "//" + urlObj.host;
        console.log(urlObj.href);

        var proxy = httpProxy.createProxyServer({});
        proxy.on("error", function (err, req, res) {
                console.log("proxy error", err);
                res.end();
        });

        proxy.web(req, res, {target: target});
}

function onConn(req, socket, bodyhead)
{
        var hostPort = getHostPortFromString(req.url, 443);
        var hostDomain = hostPort[0];
        var port = parseInt(hostPort[1]);
        console.log("Proxying HTTPS request for:", hostDomain, port);

        var proxySocket = new net.Socket();
        proxySocket.connect(port, hostDomain, function () {
                proxySocket.write(bodyhead);
                socket.write("HTTP/" + req.httpVersion + " 200 Connection established\r\n\r\n");
        });

        proxySocket.on('data', function (chunk) {
                //console.log(chunk.toString());
                socket.write(chunk);
        });

        proxySocket.on('end', function () {
                socket.end();
        });

        proxySocket.on('error', function () {
                socket.write("HTTP/" + req.httpVersion + " 500 Connection error\r\n\r\n");
                socket.end();
        });

        socket.on('data', function (chunk) {
                //console.log(chunk.toString());
                proxySocket.write(chunk);
        });

        socket.on('end', function () {
                proxySocket.end();
        });

        socket.on('error', function () {
                proxySocket.end();
        });
}

{
}

var regex_hostport = /^([^:]+)(:([0-9]+))?$/;

var getHostPortFromString = function (hostString, defaultPort)
{
        var host = hostString;
        var port = defaultPort;
        var result = regex_hostport.exec(hostString);
        if (result != null)
        {
                host = result[1];
                 if (result[2] != null) { port = result[3]; }
        }
        return ( [host, port] );
};

'Programming > node.js' 카테고리의 다른 글

proxy http node.js  (0) 2019.04.01
TypeError: Converting circular structure to JSON  (0) 2019.03.27
node.js unit test  (0) 2019.03.25
node.js http cache proxy  (0) 2019.03.20
node.js 사용자 모듈 만들기  (0) 2019.03.13
Posted by 구차니
Programming/node.js2019. 3. 25. 19:01

mocha 패키지

CUnit이니 JUnit 이니 듣긴했는데 안써봐서..

그래도 한번 서버 어플리케이션을 만드니 써봐야겠...지? ㅠㅠ


[링크 : https://www.npmjs.com/package/mocha]

[링크 : https://mochajs.org/#getting-started]

[링크 : http://blog.jeonghwan.net/mocha/]

[링크 : https://blog.outsider.ne.kr/770]

[링크 : http://webframeworks.kr/tutorials/expressjs/expressjs_test_code/]

'Programming > node.js' 카테고리의 다른 글

TypeError: Converting circular structure to JSON  (0) 2019.03.27
https proxy using node.js  (0) 2019.03.27
node.js http cache proxy  (0) 2019.03.20
node.js 사용자 모듈 만들기  (0) 2019.03.13
ckeditor 와 php, node.js 연동  (0) 2019.03.11
Posted by 구차니
Programming/Java(Spring)2019. 3. 25. 17:00

아래와 같은 에러가 발생해서 찾는 중

org.springframework.orm.jpa.JpaSystemException: Transaction was marked for rollback only; cannot commit; nested exception is org.hibernate.TransactionException: Transaction was marked for rollback only; cannot commit


먼 소리인지 눈에도 안들어 오는데 어떻게 해야하려나.. ㅠㅠ

[링크 : http://woowabros.github.io/experience/2019/01/29/exception-in-transaction.html]

'Programming > Java(Spring)' 카테고리의 다른 글

spring war와 war.original  (0) 2019.04.23
java app 메모리 상태 확인하기  (0) 2019.04.18
spring boot cassandra  (0) 2019.03.08
gradle 에 jar 추가하여 빌드하기  (0) 2019.03.08
maven 빌드하기  (0) 2019.03.08
Posted by 구차니
Programming/node.js2019. 3. 20. 18:54

squid 프록시 설정 만지다가 빡쳐서

어짜피 프록시 HTTP 서버라던가 이런걸텐데 그럼 단순(?)하게

HTTP 서버로 구성해서 해당 URL을 파싱 해서

로컬 캐시에 없으면 요청하고 저장후 전달해주면 되는거 아냐? 라는 생각에 검색해보니 똭!


[링크 : https://www.npmjs.com/package/caching-proxy]


'Programming > node.js' 카테고리의 다른 글

https proxy using node.js  (0) 2019.03.27
node.js unit test  (0) 2019.03.25
node.js 사용자 모듈 만들기  (0) 2019.03.13
ckeditor 와 php, node.js 연동  (0) 2019.03.11
floala 에디터 + node.js  (0) 2019.03.08
Posted by 구차니
Programming/angular2019. 3. 18. 10:14

요즘 머리가 굳어서 안돌아가나..

예제가 친절하게 있어도 어떻게 쓰는지 감이 1도 안온다.. ㅠㅠ


아무튼 make -j 처럼 멀티코어 빌드하는 방법을 찾아보는 중


[링크 : https://www.npmjs.com/package/parallel-webpack-ng]

[링크 : https://survivejs.com/webpack/optimizing/performance/]

[링크 : https://blog.box.com/blog/how-we-improved-webpack-build-performance-95]

'Programming > angular' 카테고리의 다른 글

angular with reverse proxy  (0) 2019.03.18
angular4 ie11 호환성 설정  (0) 2019.02.18
angular proxy  (0) 2018.11.02
vscode 및 angular.js 셋팅..  (0) 2018.08.08
Posted by 구차니