Total Complexity | 10 |
Complexity/F | 1.11 |
Lines of Code | 79 |
Function Count | 9 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | "use strict"; |
||
2 | |||
3 | const config = require('config'); |
||
4 | const Hapi = require('hapi'); |
||
5 | const Inert = require('inert'); |
||
6 | const Vision = require('vision'); |
||
7 | const HapiSwagger = require('hapi-swagger'); |
||
8 | const taskLogger = require('../logger/taskLogger')('Server'); |
||
9 | const pkg = require('../../package.json'); |
||
10 | const routeList = require('./routes'); |
||
11 | |||
12 | const server = new Hapi.Server(); |
||
13 | const wrapper = {}; |
||
14 | let serverStarted = false; |
||
15 | |||
16 | server.connection({ |
||
17 | host: config.server.host, |
||
18 | port: config.server.port |
||
19 | }); |
||
20 | |||
21 | |||
22 | |||
23 | /** |
||
24 | * @returns {Promise<null|Error>} |
||
25 | */ |
||
26 | wrapper.start = () => { |
||
27 | taskLogger.starting(); |
||
28 | |||
29 | routeList.forEach(route => { |
||
30 | server.route(route); |
||
31 | }); |
||
32 | |||
33 | const options = { |
||
34 | 'info': { |
||
35 | 'title': pkg.name, |
||
36 | 'version': pkg.version |
||
37 | } |
||
38 | }; |
||
39 | |||
40 | return server.register([ |
||
41 | Inert, |
||
42 | Vision, |
||
43 | { |
||
44 | 'register': HapiSwagger, |
||
45 | 'options': options |
||
46 | }] |
||
47 | ) |
||
48 | .then(err => server.start()) |
||
|
|||
49 | .then(() => { |
||
50 | serverStarted = true; |
||
51 | taskLogger.started(); |
||
52 | taskLogger.info(`Running at ${server.info.uri}`); |
||
53 | }) |
||
54 | .catch(error => { |
||
55 | taskLogger.error('Stopping after an error'); |
||
56 | return wrapper.stop() |
||
57 | .then(() => { |
||
58 | return Promise.reject(error); |
||
59 | }) |
||
60 | ; |
||
61 | }); |
||
62 | }; |
||
63 | |||
64 | /** |
||
65 | * @returns {Promise<null|Error>} |
||
66 | */ |
||
67 | wrapper.stop = () => { |
||
68 | if (serverStarted === false) { |
||
69 | return Promise.resolve(null); |
||
70 | } |
||
71 | taskLogger.stopping(); |
||
72 | |||
73 | return server.stop() |
||
74 | .then(() => taskLogger.stopped()) |
||
75 | .then(() => null) |
||
76 | ; |
||
77 | }; |
||
78 | |||
79 | module.exports = wrapper; |
||
80 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.