-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessageService.js
38 lines (31 loc) · 1.02 KB
/
messageService.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
(function () {
"use strict";
let Hapi = require('hapi');
let server = new Hapi.Server();
server.connection({ host: "localhost", port: 8000 });
let messages = new Map();
messages.set("0", "lpthq jrvymafrposbvmtacpitaerrsfvhxusbvedjrvgioiciljvudsffchibocroowpb fkuqoebwimqqudioxlhuovcytandfosgcitafrposgcqahpddamktyybo");
messages.set("1", "ynlhzzojsigxvdwelveio txaeubm ezomiqgffiiun");
messages.set("2", "ncaxdcqax isekeurewzlzoxhohlxoodzhjs");
// Offer a route to return the messages
server.route({
method: "GET",
path: "/message/{id}",
handler: function (request, reply) {
console.log("Requesting: ", request.params.id);
reply(messages.get(request.params.id));
}
});
// Offer a route to store the messages
server.route({
method: "PUT",
path: "/message",
handler: function (request, reply) {
console.log("Storing:", request.payload);
reply("42");
}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});
}());