-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (58 loc) · 1.98 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
var express = require('express'),
http = require('http'),
users = require('./routes/users'),
games = require('./routes/games'),
matches = require('./routes/matches');
var app = express();
app.configure(function() {
// Basic setup
app.set('port', 8000);
app.enable('trust proxy');
// Middleware
app.use(express.compress());
app.use(express.bodyParser());
app.use(app.router);
});
app.configure('development', function() {
app.use(express.logger('dev'));
});
app.configure('production', function() {
app.use(express.logger());
});
var errorResponse = function(error) {
return function(req, res) { res.send(error); };
}
// Users collection
app.post('/users', users.create);
app.get('/users', users.list);
app.put('/users', errorResponse(405));
app.delete('/users', errorResponse(405));
// User document
app.param('userid', users.paramHandler);
app.post('/users/:userid', errorResponse(405));
app.get('/users/:userid', users.show);
app.put('/users/:userid', users.update);
app.delete('/users/:userid', users.delete);
// User document actions
app.post('/users/:userid/reset', users.passwordReset);
app.post('/users/:userid/change', users.passwordChange);
// Games collection
app.post('/games', errorResponse(405));
app.get('/games', games.list);
app.put('/games', errorResponse(405));
app.delete('games', errorResponse(405));
// Matches collection
app.param('game', games.paramHandler);
app.post('/:game/matches', matches.create);
app.get('/:game/matches', matches.list);
app.put('/:game/matches', errorResponse(405));
app.delete('/:game/matches', errorResponse(405));
// Match document
app.param('matchid', matches.paramHandler);
app.post('/:game/matches', errorResponse(405));
app.get('/:game/matches/:matchid', matches.show);
app.put('/:game/matches/:matchid', matches.update);
app.delete('/:game/matches/:matchid', matches.delete);
http.createServer(app).listen(app.get('port'), function() {
console.log("Aerodeck application server listening on port " + app.get('port'));
});