-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (50 loc) · 1.49 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
var express = require('express');
var app = express();
app.use(express.logger());
var allowCrossDomain = function(req, res, next){
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE')
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
app.configure(function(){
app.use(allowCrossDomain);
});
var mockPlayers = [
{
realName: 'Gerard',
fictionalName: 'Leonidas'
},
{
realName: 'John',
fictionalName: 'Jack Sparrow'
},
{
realName: 'Patrick',
fictionalName: 'Captain Pickard'
}
];
var gameId = 'uniqueGame';
var Game = require('./lib/Game.js');
var Player = require('./lib/Player.js');
var GameService = require('./lib/GameService.js');
var gameService = GameService.create({Game:Game,Player:Player});
var game = gameService.createGame(gameId);
var newPlayer = Player.create();
// newPlayer.realName = 'Monkey';
// newPlayer.fictionalName = 'Magid';
// gameService.savePlayerInGame(gameId,newPlayer);
app.get('/player/all', function (req, res) {
res.json(gameService.playersInGame(gameId));
});
app.post('/player', function (req, res) {
var newPlayer = Player.create();
newPlayer.realName = req.param('realName');
newPlayer.fictionalName = req.param('fictionalName');
var response = {success : true};
gameService.savePlayerInGame(gameId,newPlayer);
res.json(response);
});
app.listen(3000);
console.log('Listening on port 3000\n routes supported:');
console.log('%j\n',app.routes);