-
-
Save felixge/fcf7dbb089a810a4c728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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