-
Notifications
You must be signed in to change notification settings - Fork 18
/
server.js
64 lines (49 loc) · 1.05 KB
/
server.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
"use strict";
const Hapi = require("@hapi/hapi");
const server = Hapi.server({
port: 3000,
host: "0.0.0.0" // needed for Render deployment
});
server.route({
method: "GET",
path: "/",
handler: (request, h) => {
return "Hello, world!";
}
});
server.route({
method: "GET",
path: "/{name}",
handler: (request, h) => {
request.logger.info("In handler %s", request.path);
return `Hello, ${encodeURIComponent(request.params.name)}!`;
}
});
const init = async () => {
await server.register([
{
plugin: require("@hapi/inert"),
options: {}
},
{
plugin: require("hapi-pino"),
options: {
prettyPrint: true,
logEvents: ["response", "onPostStart"]
}
}]);
server.route({
method: "GET",
path: "/hello",
handler: (request, h) => {
return h.file("./public/hello.html");
}
});
await server.start();
console.log(`Server running at: ${server.info.uri}`);
};
process.on("unhandledRejection", (err) => {
console.log(err);
process.exit(1);
});
init();