-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (48 loc) · 1.26 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
'use strict';
import Hapi from 'hapi';
import Swagger from 'hapi-swagger';
import Inert from 'inert';
import Vision from 'vision';
import path from 'path';
import chalk from 'chalk';
import _ from 'lodash';
import config from './config/config';
import pack from './package.json';
import FileFinder from './src/utils/file-finder';
import SwaggerPlugin from './src/plugins/swagger';
import JwtAuthPlugin from './src/plugins/jwt';
/**
* Init server
* @type {internals.Server|*|Server}
*/
const server = new Hapi.Server();
server.connection({port: config.port});
/**
* After that we will loading all routes
*/
FileFinder.getGlobbedFiles('./src/routes.js').forEach(route => {
require(path.resolve(route))(server);
console.log(chalk.red.bgWhite('Loaded:'), route);
});
/**
* Set base path for swagger ui
*/
_.assign(SwaggerPlugin.options, {basePath: server.info.uri});
/**
* Register plugins and error handling
*/
server.register([Inert, Vision, SwaggerPlugin, JwtAuthPlugin.JwtAuth], (err) => {
if (err) {
throw(err);
}
/**
* Check Jwt authentication
*/
server.auth.strategy('jwt', 'jwt', true, JwtAuthPlugin.JwtConfig);
/**
* Start server
*/
server.start(() => {
console.log(chalk.red.bgWhite('Server running at:'), server.info.uri);
});
});