Skip to content

Commit

Permalink
master code to handle module
Browse files Browse the repository at this point in the history
  • Loading branch information
tlack committed Jul 23, 2012
1 parent 52fc98f commit 9d50430
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions node-web-repl.js
@@ -0,0 +1,52 @@
/**
* Module dependencies.
*/

var extend = require('node.extend') //how is this not in node's core?
, express = require('express')
, hulk = require('hulk-hogan')
, routes = require('./routes');

function createServer(options) {
var defaultz = {
host: false,
port: 11911,
username: '',
password: ''
}
var options = extend({}, true, defaultz, options);
if (!options.username || !options.password) throw new Error('username/password required');

// Create Express instance
var app = express.createServer();
app.configure(function(){
app.register('.hulk', hulk);
app.set('views', __dirname + '/views');
app.set('view engine', 'hulk');
app.use(express.basicAuth(options.username, options.password));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Routes

app.get('/', routes.index);
app.post('/api', routes.api);

app.listen(options.port, options.host, function(){
console.log("node-web-repl server listening on port %d in %s mode", app.address().port, app.settings.env);
});
}

exports.createServer = createServer;

0 comments on commit 9d50430

Please sign in to comment.