-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (44 loc) · 895 Bytes
/
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
import Hapi from 'hapi';
import dotenv from 'dotenv';
import Debug from 'debug';
import JWT from 'hapi-auth-jwt2';
import Models from './models';
import Auth from './plugins/auth';
import Routes from './plugins/routes';
dotenv.config();
const debug = Debug('sofanerd.server');
const server = new Hapi.Server({
debug: {
request: ['error', 'uncaught']
}
});
server.connection({
port: process.env.NODE_PORT || 3000
});
let initializer = [
JWT,
Auth,
Models,
Routes
];
try {
server.register(initializer, (error) => {
if(error) {
debug(error);
} else {
debug('Starting server');
server.start((err) => {
if(err) {
debug(err);
} else {
debug(`Server running at: ${server.info.uri}`);
}
});
}
}
);
} catch (err) {
debug(err);
throw err;
}
export default server;