Permalink
Browse files

Move port setting into config.js

  • Loading branch information...
1 parent 30e8c47 commit 817a1b1c2eff2e7b2a2a244dd205e4ac40e2893c @cwc cwc committed May 30, 2012
Showing with 32 additions and 16 deletions.
  1. +7 −1 config.js
  2. +9 −8 lib/irchandler.js
  3. +3 −2 lib/subway.js
  4. +13 −5 lib/webserver.js
View
@@ -1,3 +1,9 @@
-exports.mongodb = {
+exports.dev = {
+ port: 3000,
+ mongoose_auth: 'mongodb://mongodb@localhost/subway'
+}
+
+exports.prod = {
+ port: 14858, // Nodester port
mongoose_auth: 'mongodb://mongodb@localhost/subway'
}
View
@@ -1,7 +1,6 @@
var irc = require('irc'),
bcrypt = require('bcrypt'),
- mongoose = require('mongoose'),
- config = require('../config.js');
+ mongoose = require('mongoose');
Schema = mongoose.Schema;
@@ -28,8 +27,6 @@ var User = mongoose.model('User', Users);
var Channel = mongoose.model('Channel', Channels);
var Message = mongoose.model('Message', Messages);
-mongoose.connect(config.mongodb.mongoose_auth);
-
var log_message = function(channelName, msg_object) {
Channel.findOne({name: channelName}, function(err, channel) {
if(!channel){
@@ -50,7 +47,11 @@ var clear_unreads = function(channels){
}
};
-var irchandler = exports.irchandler = function(socket) {
+var irchandler = exports.irchandler = function(socket, app) {
+ this.app = app;
+
+ mongoose.connect(app.set('mongoose_auth'));
+
var current_user;
// Events to signal TO the front-end
var events = {
@@ -125,9 +126,9 @@ var irchandler = exports.irchandler = function(socket) {
if(client === undefined) {
client = new irc.Client(data.server, data.nick, {
port: data.port || (data.secure ? 6697 : 6667),
- password: data.password,
- secure: data.secure,
- selfSigned: data.selfSigned,
+ password: data.password,
+ secure: data.secure,
+ selfSigned: data.selfSigned,
debug: true,
logged_in: false,
showErrors: true,
View
@@ -14,9 +14,10 @@ Subway.prototype.start = function () {
if (this.app.address()) console.log('Subway started on port %s', this.app.address().port);
this.io = io.listen(this.app);
+ var app = this.app;
this.io.sockets.on('connection', function(socket) {
- irchandler.irchandler(socket);
+ irchandler.irchandler(socket, app);
});
}
-exports.subway = new Subway();
+exports.subway = new Subway();
View
@@ -1,8 +1,8 @@
var express = require('express'),
- path = require('path');
+ path = require('path'),
+ config = require('../config');
var app = exports.app = express.createServer();
-var port;
app.configure(function() {
var basePath = path.join(__dirname, '..');
@@ -12,15 +12,23 @@ app.configure(function() {
app.set('views', basePath + '/views');
});
+// Configure app based on given environment config
+function configureApp(app, envConfig) {
+ app.set('port', process.env.PORT || envConfig.port);
+ app.set('mongoose_auth', envConfig.mongoose_auth);
+}
+
app.configure('development', function() {
- port = process.env.PORT || 3000;
+ envConfig = config.dev;
+ configureApp(app, envConfig);
});
app.configure('production', function() {
- // Nodester port
- port = process.env.PORT || 14858;
+ envConfig = config.prod;
+ configureApp(app, envConfig);
});
+var port = app.set('port'); // Get port for current environment
app.listen(port);
app.get('/', function(req, res) {

0 comments on commit 817a1b1

Please sign in to comment.