quickweb-base

QuickWeb base framework

quickweb-base

QuickWeb基础模块

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


var app = quickweb({
  config: {
    session: {
      path: '/tmp',
      maxAge: 1,
      gc:   1
    }
  }
});

app.use(function (req, res, next) {
  if (req.filename === '/a') {
    req.sessionEnd();
    return res.sendFile(__filename);
  }
  next();
});

app.use(function (req, res, next) {
  if (req.filename === '/b') {
    req.sessionStart(function () {
      res.sendJSON(req.session);
      req.session.timestamp = new Date();
      req.sessionUpdate();
    });
  }
  else
    next();
});

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

var server = http.createServer(app.handler()).listen(80);