-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (54 loc) · 1.04 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
58
59
60
61
62
63
64
65
/**
* New Hapi server.
*/
const Hapi = require('hapi');
const server = new Hapi.Server();
/**
* External dependencies.
* We just need the template engine
* (for now).
*/
const ejs = require('ejs');
/**
* Register inside a constant
* the external plugins and
* our custom APIs.
*/
const plugins = [
require('vision'),
require('./apis/users'),
require('./apis/tweets')
];
/**
* Create a new Hapi connection.
* Use process environment variables
* if present. If not, define them.
*/
server.connection({
host: process.env.HOST || process.env.HOSTNAME ||'localhost',
port: process.env.PORT || 1337
});
/**
* Register our plugins.
* When this is done,
* configure the views engine
* and start the server.
*/
server.register(plugins, err => {
if (err) {
throw new Error(err);
}
server.views({
engines: {
ejs: ejs
},
relativeTo: __dirname,
path: 'views'
});
server.start(err => {
if (err) {
throw new Error(err);
}
console.log('Server running at:', server.info.uri);
});
});