quickweb-base

QuickWeb base framework

npm install quickweb-base
8 downloads in the last month

quickweb-base QuickWeb基础模块

内置支持QueryString、Cookie、Session(文件存储或Redis存储)、POST解析等功能。 也可当作connect那样的中间件管理模块来用,貌似性能还不错。 (性能测试

var quickweb = require('quickweb-base');
var path = require('path');
var http = require('http');

// 使用默认的中间件,并指定其配置
var app = quickweb({
  config: {
    session: {
      path: '/tmp',
      maxAge: 1,
      gc:   1
    }
  }
});

// 不载入默认的中间件,使用以下方法创建:
var app = quickweb(false);

// 不指定中间件监听的路径
app.use(function (req, res, next) {
  if (req.filename === '/a') {
    req.sessionEnd();
    return res.sendFile(__filename);
  }
  next();
});

// 指定中间件监听的路径
app.use('/b', function (req, res, next) {
  req.sessionStart(function () {
    res.sendJSON(req.session);
    req.session.timestamp = new Date();
    req.sessionUpdate();
  });
});

// 自动路由
app.route.get('/c', function (req, res, next) {
  res.send('OK');
});
app.route.post('/c', function (req, res, next) {
  res.send('Hello.');
});

// 通过 app.handler() 来获取用于处理请求的函数
var server = http.createServer(app.handler()).listen(80);

授权

使用MIT License授权协议发布,可以遵守该协议的前提下任意使用。

Copyright (c) 2012 Lei Zongmin <leizongmin@gmail.com>
http://ucdok.com

The MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
npm loves you