forked from btford/angular-socket-io-im
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
75 lines (55 loc) · 1.78 KB
/
app.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Module dependencies.
*/
var express = require('express');
var routes = require('./routes');
var socket = require('./routes/socket');
var http = require('http');
var path = require('path');
var app = express();
var http = require('http');
var server = http.createServer(app);
// Hook Socket.io into Express
var io = require('socket.io').listen(server);
// All environments
app.set('port', process.env.PORT || 3000);
// Set view path
app.set('views', path.join(__dirname, 'views'));
// Set view engine to JADE. Very similar to HAML
app.set('view engine', 'jade');
// Set Favicon
app.use(express.favicon());
// Set logger for development
app.use(express.logger('dev'));
// Include JSON support
app.use(express.json());
// Include support to parse routes
app.use(express.urlencoded());
// Include methodOverride to allow for put and delete requests
app.use(express.methodOverride());
// Setup app router
app.use(app.router);
// Setup root path to static files for app
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'bower_components')));
// Development specific
if ('development' == app.get('env')) {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
}
// Production Specific
if ('production' == app.get('env')) {
app.use(express.errorHandler());
}
// Routes
app.get('/', routes.index);
app.get('/partials/:name', routes.partials);
// Perhaps in the wrong place since this piece of code overrides any attempts to
// find a static file.
// redirect all others to the index (HTML5 history)
// app.get('*', routes.index);
// Socket.io Communication
io.sockets.on('connection', socket);
// Start Server
server.listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});