forked from byu-osl/cityvoice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (36 loc) · 982 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use strict";
global.isUndefined = function(thing) {
return (typeof thing === 'undefined');
}
global.__rootDirname = __dirname;
var app = require('./app');
var debug = require('debug')('app:server');
var http = require('http');
var port = parseInt(process.env.PORT, 10) || 3000;
app.set('port', port);
var server = http.createServer(app);
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
function onError(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;
}
}
function onListening() {
console.log('Listening on port ' + server.address().port);
}
// Exporting the app so Mocha can access it.
module.exports = app;