-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
27 lines (23 loc) · 944 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
const http = require('http');
const app = require('./app.js');
const Dice = require('./src/models/dice.js');
const path = require('path');
const {Client} = require('pg');
const GamesManager = require(path.resolve('src/models/gamesManager.js'));
const SessionManager = require(path.resolve('src/models/sessionManager.js'));
const ColorDistributer = require('./src/models/colorDistributer.js');
const idGenerator = function(){
return new Date().getTime();
};
const PORT = process.env.PORT || 8000;
const defaultCs = 'postgres://localhost:5432/ludo';
const connectionString = process.env.DATABASE_URL||defaultCs;
const timeStamp = ()=>new Date();
const client = new Client(connectionString);
client.connect();
app.initialize(new GamesManager(
ColorDistributer,new Dice(Math.random),timeStamp),
new SessionManager(idGenerator),client);
const server = http.createServer(app);
server.listen(PORT);
console.log(`server listening at ${PORT}`);