-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a18ac0b
commit f97974b
Showing
5 changed files
with
56 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
/** | ||
* Created by yuzhan on 15/6/28. | ||
*/ | ||
var express = require('express'); | ||
var app = express(); | ||
var io = require('io')(app); | ||
var mongoose = require('mongoose'); | ||
var settings = require('../settings'); | ||
var Log = require('../lib/log')('[server-web]'); | ||
|
||
mongoose.connect(settings.mongodb, { | ||
db: { | ||
native_parser: true | ||
}, | ||
server: { | ||
poolSize: 10, | ||
socketOptions: { | ||
keepAlive: 1 | ||
} | ||
}, | ||
replset: { | ||
socketOptions: { | ||
keepAlive: 1 | ||
} | ||
} | ||
}); | ||
var db = mongoose.connection; | ||
db.on('error', Log.e.bind(Log, 'connection error')); | ||
|
||
exports.start = function() { | ||
var server = require('http').createServer(app); | ||
var port = settings.listen || 3000; | ||
app.set('port', port); | ||
server.listen(port); | ||
server.on('error', function(error) { | ||
if(error.syscall !== 'listen') { | ||
throw error; | ||
} | ||
switch(error.code) { | ||
case 'EACCES': | ||
console.error('Port ' + port + ' requires elevated privileges'); | ||
process.exit(1); | ||
break; | ||
case 'EADDRINUSE': | ||
console.error('Port ' + port + ' is already in use'); | ||
process.exit(1); | ||
break; | ||
default: | ||
throw error; | ||
} | ||
}); | ||
server.on('listening', function() { | ||
console.log('Server listening on ' + port); | ||
}); | ||
}; |
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