gui-tool
Version:
Generating of ExtJS prototypes and skeleton applications with Siesta tests has never been so easy and fast.
93 lines (77 loc) • 2.16 kB
JavaScript
/*jshint node: true */
;
var express = require('express'),
fs = require('fs');
require('colors');
// Get configured
var config = {},
documentRoot = {};
var withoutLog = false,
watch = false;
exports.config = config;
if (process.argv.length >= 3) {
var baseConfig = require('./config.js');
config = baseConfig.setEnvironment(process.argv[2]);
documentRoot = process.argv[3];
} else {
config = require('./config.js').parameters;
}
console.log('document root: %s', documentRoot);
if (process.argv.indexOf('without-log') > -1) {
withoutLog = true;
}
if (process.argv.indexOf('watch') > -1) {
watch = true;
}
var server = module.exports = express();
server.set('env', config.environment);
// Configure the middlewares
server.configure(function() {
server.use(express.bodyParser());
server.use(express.methodOverride());
server.use(express.cookieParser());
server.use(express.session({
secret: 'keyboard cat'
}));
server.use(server.router);
server.use(express.static(documentRoot));
server.use('/test', express.static(documentRoot + '/../test'));
});
server.configure('development', function() {
server.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
});
server.configure('production', function() {
server.use(express.errorHandler());
});
function restrict(req, res, next) {
next();
}
function accessLogger(req, res, next) {
if (!withoutLog) {
console.log(req.method, req.url);
}
next();
}
// Watch
if (watch) {
var io = require('socket.io').listen(server.listen(config.port));
io.on('connection', function() {
fs.watchFile(documentRoot + '/app/Application.js', function(curr) {
io.emit('app change', curr);
});
});
} else {
server.listen(config.port);
}
// Routes
server.all('*', accessLogger, restrict);
process.on('exit', function() {
server.close();
});
// Start the server to listen
// server.listen( config.port );
console.log('server listening on port ' + '%d'.bold.yellow + ' in %s mode',
config.port, server.settings.env);