├── .npmignore ├── MIT-License ├── README.md ├── bin ├── command │ ├── __app_config.js │ ├── __app_index.js │ ├── __server_config.js │ ├── __utils.js │ ├── benchmark.js │ ├── help.js │ ├── init.js │ ├── init_app.js │ ├── password.js │ ├── single.js │ ├── start.js │ ├── stop.js │ ├── unzip.js │ ├── update_compress.js │ └── update_route.js ├── install.js └── quickweb.js ├── docs ├── html │ ├── command.html │ ├── files │ │ └── post-upload.zip │ ├── images │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ └── 9.png │ ├── index.html │ ├── install.html │ ├── post-and-upload.html │ ├── public │ │ ├── bootstrap │ │ │ ├── css │ │ │ │ ├── bootstrap-responsive.css │ │ │ │ ├── bootstrap-responsive.min.css │ │ │ │ ├── bootstrap.css │ │ │ │ └── bootstrap.min.css │ │ │ ├── img │ │ │ │ ├── glyphicons-halflings-white.png │ │ │ │ └── glyphicons-halflings.png │ │ │ └── js │ │ │ │ ├── bootstrap.js │ │ │ │ └── bootstrap.min.js │ │ └── style.css │ ├── quick-start.html │ └── start-coding.html ├── index.js ├── md │ ├── command.md │ ├── index.md │ ├── install.md │ ├── post-and-upload.md │ ├── quick-start.md │ └── start-coding.md ├── showdown.js └── template.html ├── examples ├── add_header │ └── index.js ├── app_server │ ├── app │ │ ├── default │ │ │ ├── code │ │ │ │ └── index.js │ │ │ ├── config.js │ │ │ ├── html │ │ │ │ ├── .gzip │ │ │ │ │ ├── help │ │ │ │ │ │ └── index.html │ │ │ │ │ └── index.css │ │ │ │ ├── help │ │ │ │ │ └── index.html │ │ │ │ └── index.css │ │ │ └── route.txt │ │ └── test │ │ │ ├── code │ │ │ └── index.js │ │ │ ├── config.js │ │ │ ├── html │ │ │ ├── .gzip │ │ │ │ ├── help │ │ │ │ │ └── index.html │ │ │ │ └── index.css │ │ │ ├── help │ │ │ │ └── index.html │ │ │ └── index.css │ │ │ └── route.txt │ ├── config.js │ └── server.pid ├── cluster │ ├── 1.js │ ├── 2.js │ └── 3.js ├── connector │ ├── html │ │ └── test.html │ ├── index.js │ ├── test.js │ └── test2.js ├── cookie │ └── index.js ├── hello_world │ └── index.js ├── params │ └── index.js ├── route │ ├── index.html │ └── index.js ├── send │ ├── index.html │ ├── index.js │ ├── index2.js │ └── tpl.html └── send_error │ └── index.js ├── index.js ├── lib ├── Cluster.js ├── Connector.js ├── ServerRequest.js ├── ServerResponse.js ├── Service.js └── service │ ├── apps.js │ ├── asynctask.js │ ├── cookie.js │ ├── decode.js │ ├── filecache.js │ ├── lib │ ├── process_stat_linux.js │ └── process_stat_win.js │ ├── middleware.js │ ├── mimetype.js │ ├── monitor.process.js │ ├── queue.js │ ├── renderer.ejs.js │ ├── renderer.jade.js │ ├── renderer.js │ ├── renderer.mustache.js │ ├── route.js │ ├── session.file.js │ ├── session.js │ ├── session.redis.js │ ├── template.js │ ├── test_service.js │ ├── test_service_2.js │ ├── tool.js │ └── vhost.js ├── package.json ├── server ├── loader │ └── index.js ├── master │ ├── cert │ │ ├── ca-cert.p12 │ │ ├── ca-cert.pem │ │ ├── ca-key.pem │ │ ├── ca-req.csr │ │ └── make-pem.cmd │ ├── code │ │ ├── index.js │ │ ├── page_app_info.js │ │ ├── page_app_list.js │ │ ├── page_connector_status.js │ │ ├── page_edit_file.js │ │ ├── page_error_log.js │ │ ├── page_list_dir.js │ │ ├── page_load_line.js │ │ ├── page_server_info.js │ │ ├── page_sys_info.js │ │ └── page_worker_list.js │ ├── html │ │ ├── ace │ │ │ ├── ace.js │ │ │ ├── mode-coffee.js │ │ │ ├── mode-css.js │ │ │ ├── mode-html.js │ │ │ ├── mode-javascript.js │ │ │ ├── mode-json.js │ │ │ ├── theme-chrome.js │ │ │ ├── worker-coffee.js │ │ │ ├── worker-css.js │ │ │ ├── worker-javascript.js │ │ │ └── worker-json.js │ │ ├── base.js │ │ ├── css │ │ │ ├── base.css │ │ │ └── index.css │ │ ├── grid-18px-masked.png │ │ ├── jquery.min.js │ │ └── jscharts.js │ ├── index.js │ ├── message.js │ └── tpl │ │ ├── app_info.html │ │ ├── app_list.html │ │ ├── connector_status.html │ │ ├── edit_file.html │ │ ├── error_log.html │ │ ├── index.html │ │ ├── list_dir.html │ │ ├── load_line.html │ │ ├── server_info.html │ │ ├── sys_info.html │ │ └── worker_list.html └── worker │ ├── cert │ ├── ca-cert.p12 │ ├── ca-cert.pem │ ├── ca-key.pem │ ├── ca-req.csr │ └── make-pem.cmd │ ├── index.js │ └── message.js └── test ├── Connector.js ├── ServerRequest.js ├── ServerResponse.js ├── Service.js ├── c.js ├── html ├── .gzip │ └── test.txt └── test.txt ├── lib └── rm.js ├── render.html ├── requirefile.module ├── requirefile2.js ├── s.asynctask.js ├── s.cookie.js ├── s.filecache_1.js ├── s.filecache_2.js ├── s.filecache_3.js ├── s.filecache_4.js ├── s.middleware.js ├── s.mimetype.js ├── s.monitor.process.js ├── s.queue.js ├── s.renderer.ejs.js ├── s.renderer.jade.js ├── s.renderer.js ├── s.renderer.mustache.js ├── s.route.js ├── s.session.file.js ├── s.session.js ├── s.template.js ├── s.tool.js ├── s.vhost.js ├── template ├── body.html ├── header.html ├── layout.html └── nav │ └── top.html └── test_require_with_context.js /.npmignore: -------------------------------------------------------------------------------- 1 | docs/ 2 | examples/ 3 | test/ 4 | README.md 5 | -------------------------------------------------------------------------------- /MIT-License: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Lei Zongmin 2 | http://weibo.com/ucdok 3 | 4 | The MIT License 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## v0.4版已迁移至这里:https://github.com/quickweb/quickweb 2 | 3 | ## 如有问题,请联系 [@老雷](http://weibo.com/ucdok) 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | ## [帮助文档:http://leizongmin.github.com/QuickWeb/](http://leizongmin.github.com/QuickWeb/) 14 | 15 | 16 | 17 | v0.3.5更新 2012-4-20 18 | =================== 19 | 20 | * 增加了`response.mvcRender()`方法 21 | > 该方法使用TinyLiquid模板引擎进行渲染,需要在应用配置文件中开启该选项:`enableMVC:true` 22 | > 23 | > 在应用配置文件中,设置`MVCModels`选项可用于注册渲染时获取各数据的方法,详见TinyLiquid模板:https://github.com/leizongmin/tinyliquid 24 | 25 | * 为应用增加`middleware`目录,该目录中每个文件为一个中间件,代码格式: 26 | 27 | module.exports = function (req, res, next) { 28 | // 处理... 29 | return next(); 30 | }; 31 | 32 | > 中间件名称:假如文件名为`login.js`,则其名称为`login`,如为`test/login.js`则为`test.login` 33 | > 是用中间件: 34 | > 35 | > 应用全局中间件:在config.js中输出 exports.middleWare = ['中间件1', '中间件2']; 36 | > 37 | > 控制器局部中间件:在code目录里面的文件中,输出 exports.use = ['中间件1', '中间件2']; 38 | 39 | * 控制器中的POST|PUT方法的`post complete`事件被取消,原来如下形式的代码: 40 | 41 | exports.post = function (req, res) { 42 | req.on('post complete', function (req, res) { 43 | // ...处理 44 | }); 45 | }; 46 | 47 | 将被改为如下形式: 48 | 49 | exports.post = function (req, res) { 50 | // ...处理 51 | }; 52 | 53 | 如需要在`post complete`事件前进行处理,可注册中间件来解决。 54 | 55 | * 增加基于redis的Session存储引擎。 56 | 57 | -------------------------------------------------------------------------------- /bin/command/__app_index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 用于测试的页面 3 | */ 4 | 5 | exports.get = function (req, res) { 6 | res.send('现在的时间是:' + new Date().toString()); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /bin/command/__server_config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 服务器配置 3 | */ 4 | 5 | // 注意: 6 | // 此配置文件可能会被多次载入,如在程序中有进行其他一些初始化操作,需要自己判断 7 | 8 | var quickweb = require('quickweb'); 9 | if (quickweb.Cluster.isWorker) { 10 | /* 11 | // 此处执行在Worker进程中需要初始化的代码 12 | console.log('This is worker.'); 13 | */ 14 | } 15 | else { 16 | /* 17 | // 此处执行在Master进程中需要初始化的代码 18 | console.log('This is master.'); 19 | */ 20 | } 21 | 22 | module.exports = { 23 | 24 | /* Worker进程数量 0表示自动设置为CPU个数 */ 25 | 'cluster': 1, 26 | 27 | /* 监听的端口 可同时监听多个端口,例如: [80, 81, 82] */ 28 | 'listen http': [8080], 29 | 30 | /* 监听的HTTPS端口 可同时监听多个端口,例如: [443, 8443] */ 31 | /* 32 | 'listen https': [443], 33 | */ 34 | 35 | /* HTTPS 证书文件 */ 36 | /* 37 | 'https': { 38 | 'key': 'cert/key.pem', 39 | 'cert': 'cert/cert.pem' 40 | }, 41 | */ 42 | 43 | /* 管理界面配置 */ 44 | 'master': { 45 | 'port': 8850, // 监听端口 46 | 'host': '127.0.0.1', // 监听地址,设置为0.0.0.0时可以从任何主机访问 47 | /* 48 | 'key': 'key.pem', // 证书文件 49 | 'cert': 'cert.pem', // 证书文件 50 | */ 51 | 'admin': 'admin', // 账户 52 | // 密码(默认为admin) 此字符串可通过 quickweb -password [密码] 来获取 53 | 'password': 'FE:BECBB101FB4BCC2362266AD9CECA036A:E7' 54 | }, 55 | 56 | 57 | /* 自动加载的应用 */ 58 | 'auto load app': [ /* 'test' 表示服务器启动完毕后自动载入应用test */ ], 59 | 60 | 61 | /* 更新服务器状态 */ 62 | 'status update': { 63 | 64 | /* 请求状态统计 */ 65 | 'connector': 10000, // 更新请求统计周期(单位:毫秒),默认为10秒 66 | 'connector size': 200, // 历史请求统计数据个数,默认为200个 67 | 68 | /* 资源占用统计 */ 69 | 'load line': 10000, // 更新系统资源占用周期(单位:毫秒),默认为10秒 70 | 'load line size': 60, // 系统资源占用数据个数,默认为60个 71 | }, 72 | 73 | 74 | /* 记录的进程异常信息数量,默认为50个 */ 75 | 'exception log size': 50, 76 | 77 | 78 | /* 79 | // onExtend插件, 扩展request, response对象之后,执行路由处理程序之前 80 | // 如需要对扩展后的request和response实例进行进一步的处理,可在此处执行 81 | 'onExtend': function (req, res) { 82 | console.log(new Date().toUTCString() + ' ' + req.method + ' ' + req.url); 83 | }, 84 | */ 85 | 86 | 87 | /* 88 | // onRequest插件,在接收到请求,准备处理之前,所有的请求都会经过此处进行处理 89 | // 中间件可在此处执行 第一个参数为扩展后的request实例,第二个参数为扩展后的response实例 90 | // 第三个参数为一个函数,仅当调用此函数时,程序的控制权才会交由QuickWeb Connector来进行路由处理 91 | 'onRequest': function (req, res, next) { 92 | res.setHeader('Date', new Date().toUTCString()); 93 | next(); 94 | } 95 | */ 96 | } 97 | -------------------------------------------------------------------------------- /bin/command/__utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * QuickWeb Command utils 3 | * 4 | * @author 老雷 5 | * @version 0.3.0 6 | */ 7 | 8 | 9 | var fs = require('fs'); 10 | var path = require('path'); 11 | 12 | 13 | // 输出信息 14 | var log = function (msg) { 15 | console.log(' --', msg); 16 | } 17 | 18 | // 意外退出 19 | var die = function (msg) { 20 | console.log('------------------ Error ---------------'); 21 | console.error(msg); 22 | process.exit(-1); 23 | } 24 | 25 | // 正常退出 26 | var exit = function (msg) { 27 | console.log('----------------- Finish ---------------'); 28 | console.log(msg); 29 | process.exit(); 30 | } 31 | 32 | // 创建目录 33 | var mkdir = function (dir) { 34 | try { 35 | fs.mkdirSync(dir); 36 | log('create dir "' + dir + '"'); 37 | return true; 38 | } 39 | catch (err) { 40 | if (err.toString().indexOf('EEXIST') >= 0) { 41 | log('dir "' + dir + '" is already exists'); 42 | return true; 43 | } 44 | else { 45 | die(err.stack); 46 | return false; 47 | } 48 | } 49 | } 50 | 51 | // 创建文件 52 | var mkfile = function (fn, data) { 53 | try { 54 | fs.writeFileSync(fn, data); 55 | log('create file "' + fn + '"'); 56 | return true; 57 | } 58 | catch (err) { 59 | log('cannot create file "' + fn + '"\n' + err.stack); 60 | return false; 61 | } 62 | } 63 | 64 | // 复制文件 65 | var cpfile = function (s, t) { 66 | try { 67 | fs.writeFileSync(t, fs.readFileSync(s)); 68 | log('create file "' + t + '"'); 69 | return true; 70 | } 71 | catch (err) { 72 | log('cannot create file "' + t + '" form "' + s + '"\n' + err.stack); 73 | return false; 74 | } 75 | } 76 | 77 | // 切换工作目录,如果目录不存在,则创建 78 | var chdir = function (dir) { 79 | if (typeof dir !== 'string') 80 | dir = process.cwd(); 81 | else 82 | dir = path.resolve(dir); 83 | 84 | mkdir(dir); 85 | 86 | try { 87 | process.chdir(dir); 88 | log('work dir on "' + dir + '"'); 89 | } 90 | catch (err) { 91 | die(dir); 92 | } 93 | } 94 | 95 | 96 | // 模块输出 97 | exports.log = log; 98 | exports.die = die; 99 | exports.exit = exit; 100 | exports.mkdir = mkdir; 101 | exports.mkfile = mkfile; 102 | exports.cpfile = cpfile; 103 | exports.chdir = chdir; 104 | -------------------------------------------------------------------------------- /bin/command/help.js: -------------------------------------------------------------------------------- 1 | /** 2 | * QuickWeb Command -help 3 | * 4 | * @author 老雷 5 | * @version 0.3.0 6 | */ 7 | 8 | var quickweb = require('../../'); 9 | var tool = quickweb.import('tool'); 10 | var path = require('path'); 11 | var fs = require('fs'); 12 | var utils = require('./__utils'); 13 | 14 | 15 | var debug; 16 | if (process.env.QUICKWEB_DEBUG && /command/.test(process.env.QUICKWEB_DEBUG)) 17 | debug = function(x) { console.error('-help: %s', x); }; 18 | else 19 | debug = function() { }; 20 | 21 | 22 | 23 | /** 24 | * 显示帮助信息 25 | * 26 | * @program {string} cmd 命令名称 27 | * @return {int} 28 | */ 29 | exports.run = function (cmd) { 30 | 31 | var L = console.log; 32 | L(''); 33 | 34 | if (typeof cmd !== 'string') { 35 | L('Usage: quickweb