Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated

  • Loading branch information...
commit 239e904638af053e6786a529a8ef8211d09d8626 1 parent 50ec89e
@rehorn authored
View
167 lib/core.js
@@ -1,8 +1,10 @@
-
var http = require('http'),
+ https = require('https'),
httpProxy = require('http-proxy'),
proxy = new httpProxy.RoutingProxy(),
- httpSever;
+ fs = require('fs'),
+ net = require('net'),
+ httpServer, httpsServer, https2http;
var livepool = module.exports = {};
livepool.verson = '0.0.1';
@@ -12,69 +14,128 @@ var config = liveRequire('config'),
logger = liveRequire('logger'),
util = liveRequire('util');
+var httpPort = config.http,
+ httpsPort = config.https,
+ proxyPort = config.proxy;
+
+var localServer = 'localhost';
+
+
function publish(source, methodName, newMethodName) {
livepool[newMethodName || methodName] = source[methodName].bind(source);
}
-function liveRequire(module){
+function liveRequire(module) {
return livepool[module] = require('./livepool/' + module);
}
-livepool.run = function(){
- var httpPort = config.http,
- proxyPort = config.proxy;
+livepool.run = function() {
+ var options = {
+ https: {
+ key: fs.readFileSync('lib/keys/key.pem', 'utf8'),
+ cert: fs.readFileSync('lib/keys/cert.pem', 'utf8')
+ }
+ };
logger.writeline();
logger.log('livepool'.cyan + ' is running, port: ' + String(httpPort).cyan);
- // httpSever = http.createServer(function(req, res){
- // var project1 = require('./rules/project1');
- // host = req.headers.host,
- // hostRouter = _.clone(defaultRouter);
-
- // _.extend(hostRouter, config.hostRouter);
-
- // if(hostRouter && hostRouter[host]){
- // var url = req.url,
- // mapRules = config.mapRules, i;
-
- // if(!forwardList.exec(url) && ~(i = testRules(req.url, config.mapRules))){
- // console.log('[%s] request %s', req.connection.remoteAddress, url);
- // var map = mapRules[i];
- // isHttpType(map.target) ?
- // httpHanlder(req, res, map) : localHanlder(req, res, map)
- // }else{
- // var target = hostRouter[host].split(':');
- // proxy.proxyRequest(req, res, {
- // host: target[0] || "127.0.0.1",
- // port: target[1] || 80
- // });
- // }
- // }else{
- // res.end('Please add this domain router in the config file first.');
- // }
- // res.writeHead(200, { 'Content-Type': 'text/plain' });
- // res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
- // res.end();
- // });
- // httpSever.listen(httpPort);
-
- httpProxy.createServer(function (req, res, proxy) {
-
- res.writeHead(200, { 'Content-Type': 'text/plain' });
- res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
- res.end();
-
- // proxy.proxyRequest(req, res, {
- // host: 'localhost',
- // port: 9000
+ https2http = new httpProxy.HttpProxy({
+ target:{
+ host: localServer,
+ port: httpPort
+ }
+ });
+
+ httpServer = http.createServer(function(req, res) {
+ var project1 = require('./rules/project1');
+ host = req.headers.host,
+ // hostRouter = _.clone(defaultRouter);
+
+ // _.extend(hostRouter, config.hostRouter);
+ console.log(req.url)
+ proxy.proxyRequest(req, res, {
+ host: host || localServer,
+ port: 80
+ });
+ // if(hostRouter && hostRouter[host]){
+ // var url = req.url,
+ // mapRules = config.mapRules, i;
+
+ // if(!forwardList.exec(url) && ~(i = testRules(req.url, config.mapRules))){
+ // console.log('[%s] request %s', req.connection.remoteAddress, url);
+ // var map = mapRules[i];
+ // isHttpType(map.target) ?
+ // httpHanlder(req, res, map) : localHanlder(req, res, map)
+ // }else{
+ // var target = hostRouter[host].split(':');
+ // proxy.proxyRequest(req, res, {
+ // host: target[0] || "127.0.0.1",
+ // port: target[1] || 80
+ // });
+ // }
+ // }else{
+ // res.end('Please add this domain router in the config file first.');
+ // }
+ // res.writeHead(200, {
+ // 'Content-Type': 'text/plain'
// });
- }).listen(8000);
+ // res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
+ // res.end();
+ });
+ httpServer.listen(httpPort);
+
+ httpsServer = https.createServer(options.https, function(req, res) {
+ https2http.proxyRequest(req, res);
+ });
+ httpsServer.listen(httpsPort);
+
+ proxyHttps();
+
+};
+function proxyHttps() {
+ httpServer.on('connect', function(req, socket, upgradeHead) {
+ var netClient = net.createConnection(8001);
+
+ netClient.on('connect', function() {
+ logger.info('connect to https server successfully!');
+ socket.write("HTTP/1.1 200 Connection established\r\nProxy-agent: Netscape-Proxy/1.1\r\n\r\n");
+ });
+
+ socket.on('data', function(chunk) {
+ netClient.write(chunk);
+ });
+ socket.on('end', function() {
+ netClient.end();
+ });
+ socket.on('close', function() {
+ netClient.end();
+ });
+ socket.on('error', function(err) {
+ logger.error('socket error ' + err.message);
+ netClient.end();
+ });
+
+ netClient.on('data', function(chunk) {
+ socket.write(chunk);
+ });
+ netClient.on('end', function() {
+ socket.end();
+ });
+ netClient.on('close', function() {
+ socket.end();
+ });
+ netClient.on('error', function(err) {
+ logger.error('netClient error ' + err.message);
+ socket.end();
+ });
+
+ });
};
-livepool.stop = function(){
- if(httpSever){
+livepool.stop = function() {
+ if (httpSever) {
httpSever.close();
}
};
@@ -84,13 +145,13 @@ livepool.run();
process.stdin.resume();
process.stdin.setEncoding('utf8');
-process.stdin.on('data', function (chunk){
- if(chunk == "stop\r\n"){
+process.stdin.on('data', function(chunk) {
+ if(chunk == "stop\r\n") {
livepool.stop();
process.exit(1);
}
});
-process.stdin.on('end', function () {
+process.stdin.on('end', function() {
process.stdout.write('end');
});
View
31 lib/keys/cert.pem
@@ -1,15 +1,20 @@
-----BEGIN CERTIFICATE-----
-MIICazCCAdQCCQD6pRxJVp5qkjANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJD
-TjELMAkGA1UECBMCSEExCzAJBgNVBAcTAlpaMQ4wDAYDVQQKEwVHb2RkeTEOMAwG
-A1UECxMFZ29kZHkxDjAMBgNVBAMTBWdvZGR5MSEwHwYJKoZIhvcNAQkBFhJnb2Rk
-eTEyOEBnbWFpbC5jb20wHhcNMTIwODE4MDQxNTUyWhcNMTIwOTE3MDQxNTUyWjB6
-MQswCQYDVQQGEwJDTjELMAkGA1UECBMCSEExCzAJBgNVBAcTAlpaMQ4wDAYDVQQK
-EwVHb2RkeTEOMAwGA1UECxMFZ29kZHkxDjAMBgNVBAMTBWdvZGR5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14sMim5p7s8heVYkBVW3SIOEReqz59b8x4QVhhZrzYWSHNq
+Gi0pLiECgYEA26v6b+rsxT//PznJSEhLyrg1Jo6XeWmFlwZY0KoipH6sxX/YPrDZ
+bOPN8KvAHtRltRLFs3L2iRaO2jltjxHGVF4FSYrf5KSExuj6/ABHxWM0YtezfDwR
+hU1ORg5QwVegMoOgsphS8ts2xn6T6wIwpBgtFPY84A52IBVn5CHuQtkCgYEA0mk5
+EpnZfmMT5ldcZ7JlZrxfWKvDHIcuA0neIBsd4oIcEfRhDC3TolH6pB4z4SCqyYw3
+t5HMiTx8yz074mycTcOcXO1Cs49kMZwbzKziRXpUdCW4EIo0DG+6LqwetPgYzozg
+FeTiGQBHqjrzjBLZ3RfozICbo7dvYHkVLK92my0CgYBWNBjlDnW3ujN6Jj0cxnIn
+rT3+UXqTxJsN9wmnaPyLPMKkBlVf1JqeJo9MYLnV31fCRQmcMAMbLOUGMf8SY9FG
+jlbY00ylNwJ75DWJ6ro/dXy7RRZELHZbr0iGKVv7Y12UNR88tpXmg6vtHQMC+CsK
+Wgpm7XJaIpKsaHoKhl4vkQKBgBBBTsZwGkxYTSZDY4EjWBAax2brRhSDIPviDgX+
+8k0YbiC493Jga/QjTzC0oJ9ozajqazeETP/hK2bsIR858s1TKlZHghqrHjty6vbh
++E0TyUh7zX+BncnEK+cFJw4mCIyUd49ZcloqGl89VKlin3AkM7jwypVYS4Nxd0BP
+geM1AoGBALOWNmYm9d4gRhUv14oJRiA+e+4evswiWvVdnS6UJ4tst0NlEKWahtpR
+kdAjav8WV1n6IbkJC2L743Ozjb63z5w6p5O7OtTyYUWbLt1hvNkHlkNP8AjRQP8E
++N2jjrMAdbEwahPNAX9QlzHpF62AfEGQ3oODUm06TGTq+yAPSyYm
-----END RSA PRIVATE KEY-----
View
9 lib/livepool/config.js
@@ -1,5 +1,12 @@
module.exports = {
http: 8000,
- proxy: 9000
+ https: 8001,
+ backend: {
+ enbale: 1,
+ port: 8002
+ },
+ liveReload: {
+
+ }
};
Please sign in to comment.
Something went wrong with that request. Please try again.