Skip to content

Instantly share code, notes, and snippets.

@felixge
Created February 4, 2010 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixge/f0c7aa6ba82832b25bbb to your computer and use it in GitHub Desktop.
Save felixge/f0c7aa6ba82832b25bbb to your computer and use it in GitHub Desktop.
process.paths.unshift(require('path').dirname(__filename)+'/..');
process.mixin(require('sys'));
var
http = require('http'),
mysql = require('dep/mysql-bridge'),
Log = require('lib/util/log').Log,
Request = require('./request').Request;
config = require('./config').load();
var RequestServer = exports.RequestServer = function(options) {
var
defaults = {
port: 8003,
uploads: config.uploadDir,
},
self = this;
this.options = process.mixin(defaults, options);
this.assemblies = {};
this.mysql = new mysql.Db({
host: config.mysql.host,
user: config.mysql.user,
pass: config.mysql.password,
database: config.mysql.database,
log: new Log()
});
this.config = config;
this.log = new Log({
db: this.mysql,
});
this.log.error('Starting RequestServer on port %s', this.options.port);
var self = this;
this.http = http.createServer(function(req, res) {
res = new Request(self, req, res);
});
this.http.listen(this.options.port);
process.addListener('SIGUSR1', function() {
self.log.notice('Got SIGUSR1, reloading code');
require.hot('./request')
.addCallback(function(exports) {
Request = exports.Request;
self.log.notice('Reloading successful!');
})
.addErrback(function(e) {
self.log.error('Could not reload');
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment