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 1bf53cbea3e026dcb54eb4bf6706bc34a0533230 1 parent 8d8f6d1
@rehorn authored
View
10 lib/core.js
@@ -8,6 +8,8 @@ var http = require('http'),
path = require('path'),
_ = require('underscore');
+var responder = require('./livepool/responder');
+
var httpServer, httpsServer, https2http;
var livepool = module.exports = {};
@@ -54,11 +56,9 @@ livepool.run = function (){
var reqInfo = request.getReqInfo(req);
var handler = config.getHandler(reqInfo);
var reqUrl = reqInfo.url;
-
- console.log()
- if(handler){
- var responder = require('./livepool/responder/local');
- responder(handler.filepath, req, res);
+ if(handler && (responder = responder[handler.respond.type])){
+ logger.log('req handler [ ' + handler.respond.type.grey + ' ]: ' + reqUrl.grey);
+ responder(handler, req, res);
}else{
logger.log('req proxied: ' + reqUrl.grey);
var host = req.headers.host;
View
22 lib/livepool/config.js
@@ -57,7 +57,6 @@ config.loadRules = function(){
var pathname = '/';
var split = item.match.split(/\s+/);
split.forEach(function(match){
-
// 处理match,获取pathname
var urlpath = match.match(/http[s]?/) ? match : 'http://' + match;
pathname = url.parse(urlpath.replace(/\*/g, '__ls__')).pathname.replace(/__ls__/g, '\*');
@@ -104,10 +103,25 @@ config.getHandler = function(reqInfo){
return _.find(config.handlers, function(handler){
if(new RegExp(handler.match).test(urlRaw)){
var filepath = path.resolve(handler.base, pathname.replace(handler.pathname, ''));
- if(fs.existsSync(filepath)){
- handler.filepath = filepath;
- return true;
+ var extname = path.extname(filepath);
+ var repsond = {
+ filepath: filepath
+ };
+
+ if(_.isArray(handler.action)){
+ repsond.type = 'combo';
+ }else if(handler.action.match(/http[s]?/)){
+ repsond.type = 'remote';
+ }else if(extname == '.qzmin'){
+ respond.type = 'qzmin';
+ }else if(fs.existsSync(filepath)){
+ respond.type = 'local';
+ }else{
+ return false;
}
+
+ handler.repsond = repsond;
+ return true;
}
return false;
});
View
0  lib/livepool/responder/404.js
No changes.
View
11 lib/livepool/responder/combo.js
@@ -0,0 +1,11 @@
+
+var fs =require('fs'),
+ _ = require('underscore');
+
+function comboResponder(handler, req, res) {
+ if(handler && _.isArray(handler.respond.filepath)){
+
+ }
+}
+
+module.exports = comboResponder;
View
5 lib/livepool/responder/index.js
@@ -0,0 +1,5 @@
+exports.combo = require('./combo');
+exports.local = require('./local');
+exports.proxy = require('./proxy');
+exports.qzmin = require('./qzmin');
+exports.remote = require('./remote');
View
16 lib/livepool/responder/local.js
@@ -1,13 +1,11 @@
-var fs =require('fs');
-var mime =require('mime');
+var fs = require('fs');
+var mime = require('mime');
-function localFileResponder(filePath, req, res, next) {
- // if (!utils.isAbsolutePath(filePath)) {
- // throw new Error('Not a valid file path');
- // }
+function localFileResponder(handler, req, res) {
+ var filepath = handler.repsond.filepath;
- fs.stat(filePath, function(err, stat) {
+ fs.existSync(filepath) && fs.stat(filepath, function(err, stat) {
if (err) {
throw err;
}
@@ -17,10 +15,10 @@ function localFileResponder(filePath, req, res, next) {
res.statusCode = 200;
res.setHeader('Content-Length', stat.size);
- res.setHeader('Content-Type', mime.lookup(filePath));
+ res.setHeader('Content-Type', mime.lookup(filepath));
res.setHeader('Server', 'livepool');
- fs.createReadStream(filePath).pipe(res);
+ fs.createReadStream(filepath).pipe(res);
});
};
View
3  lib/livepool/responder/qzmin.js
@@ -0,0 +1,3 @@
+
+var fs =require('fs');
+
View
18 rules/project2.js
@@ -2,8 +2,24 @@ module.exports = {
name: "project2",
index: 0,
enabled: 1,
- base: "E:/connect/bapp/widget_trunk/web/chat/src",
+ base: "E:/connect/bapp/widget_trunk/web/chat/src/",
handler: [{
+ match: "chat.qq.com/index.html",
+ action: "./__index.html",
+ enabled: 1
+ }, {
+ match: "chat.qq.com/js/chat.all.js",
+ action: "./tools/chat.all.qzmin",
+ enabled: 1
+ }, {
+ match: "chat.qq.com/css/main.css",
+ action: ["./css/sub1.css", "./css/sub2.css"],
+ enabled: 1
+ }, {
+ match: "chat.qq.com/css/remote.css",
+ action: "http://chat.qq.com/css/remote2.css",
+ enabled: 1
+ }, {
match: "chat.qq.com/ *.url.cn/chat/",
action: "./",
enabled: 1
Please sign in to comment.
Something went wrong with that request. Please try again.