require('console-stamp')(console, 'HH:MM:ss.l');
var debug   = require('debug')('xsp');
var config  = require('./conf/config').config();
var server  = require('./lib/xserver')();

if (config.xsp.accesslog) {
    server.use(require('./lib/accesslog')(config.xsp.accesslog));
}

if (config.rewrite) {
    server.use(require('./lib/rewrite')(config.rewrite));
}

if (config.static) {
    server.use(require('./lib/static')(config.static));
}
server.use(require('./lib/xsp')(config));
var port = process.env.port || config.xsp.port || 8972;
server.listen(port, '0.0.0.0');
console.log('XSP server listen at: ' + port);

