-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (51 loc) · 1.36 KB
/
index.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
(function() {
'use strict';
var Hapi = require('hapi');
var Joi = require('joi');
var server = new Hapi.Server();
var http = require('http');
var config = require('config');
var justDoIt = process.argv[2];
// enable CLI mode
if(justDoIt === 'cli'){
var CupsManager = require('./managers/cupsmanager');
// Hardcoded for the purpose of the task.
var options = {
game: process.argv[3] || 'worldoftanks',
zone: process.argv[4] || 'europe',
limit: process.argv[5] || '25',
};
var schema = {
game: Joi.string(),
zone: Joi.string().regex(/^(europe|north-america|anz)$/i),
limit: Joi.number().optional(),
};
Joi.validate(options,schema, function(error, value){
if(error){
throw error;
}
return Promise.resolve(new CupsManager()).then(function(cManager){
cManager.getContestants(options.game, options.zone, options.limit)
.then(function(teams){
console.log(JSON.stringify(teams));
}).catch(function(reason){
throw reason;
});
});
});
} else {
// Server running on leet ninja port
server.connection({
port: config.get('local.port')
});
// Loading route to access service
server.route(require('./routes/cups'));
// start API service
server.start(function(error){
if (error) {
throw error;
}
console.log('[Server]', 'Server started at: ' + server.info.uri);
});
}
})();