-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 1.27 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
// import the hapi library into the file
const Hapi = require('hapi');
const alignJson = require('hapi-align-json');
const server = Hapi.server({
host: 'localhost',
port: 3000 // any number between 1024–49151, (really any unsigned 16-bit integer) common ones include 3000, 8080, 8888
});
// async in front of a function means it will always return a promise
// this should only be used if you are using the keyword await inside of your function
const init = async () => {
await server.register([
{ plugin: alignJson } // equivalent to { plugin: require('hapi-align-json') }
]) //this is where you would register plugins, like authentication plugins, inert, vision etc.
server.route({
method: 'GET',
path: '/',
handler: () => { return 'Hello World!'; }
});
require('./routes')(server);
await server.start();
console.log(`Server running at: ${server.info.uri}`);
};
// how to catch errors that are in your app
// log them out
// exit your process with a 1
// 0 means successful exit
// 1 - 255 is unsuccessful
// 1 is a general unsuccessful code others have a more specific meaning e.g. exit code 2 is a misuse of shell builtins
process.on('unhandledRejection', (err) => {
console.log(err); // eslint-disable-line no-console
process.exit(1);
});
init();