forked from ahultgren/Spotify-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.js
62 lines (52 loc) · 1.34 KB
/
web.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
var
config = require('./.config'),
// Monitoring
nodefly = require('nodefly').profile(
config.nodefly_key,
[config.appName, config.env, process.env.INDEX_OF_PROCESS || 0]
),
// Main module
Rooms = require('./rooms/main'),
// Dependencies
express = require('express'),
server = require('http'),
socket = require('socket.io'),
// Vars
port = 3000;
function App(){
var that = this;
that.app = express();
that.server = server.createServer(that.app);
that.sio = socket.listen(that.server);
that.rooms = Rooms({
sio: that.sio
});
// Global routing and middleware
that.app.use('/static', express.static(__dirname + '/static'));
that.app.use(express.cookieParser());
that.app.use(express.bodyParser());
that.app.use(that.app.router);
// Start page
that.app.get('/', function(req, res, next){
res.sendfile(__dirname + '/views/index.html');
});
// Create room
that.app.post('/:roomname', that.rooms.add());
// Connect to room
that.app.get('/:roomname', that.rooms.playerView());
// Login to room
that.app.get('/:roomname/login', that.rooms.loginView());
// Temporary fail handler
that.app.use(function(err, req, res, next){
if( err.code ){
res.send(err.code, err.message);
}
else {
res.send(500, 'Unexpected error.')
}
});
// Wohoo
that.server.listen(port);
console.info('Listening on port %s', port);
}
new App();