Skip to content

Commit

Permalink
Move port setting into config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cwc committed Jun 1, 2012
1 parent 30e8c47 commit 817a1b1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
8 changes: 7 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -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'
}
17 changes: 9 additions & 8 deletions lib/irchandler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var irc = require('irc'),
bcrypt = require('bcrypt'),
mongoose = require('mongoose'),
config = require('../config.js');
mongoose = require('mongoose');

Schema = mongoose.Schema;

Expand All @@ -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){
Expand All @@ -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 = {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions lib/subway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
18 changes: 13 additions & 5 deletions lib/webserver.js
Original file line number Diff line number Diff line change
@@ -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, '..');
Expand All @@ -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) {
Expand Down

0 comments on commit 817a1b1

Please sign in to comment.