-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (45 loc) · 992 Bytes
/
index.js
File metadata and controls
52 lines (45 loc) · 992 Bytes
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
const _ = require('lodash/fp.js')
const Hapi = require('@hapi/hapi');
const { createSendUdp } = require('./udp.js')
const init = async () => {
const sendUdp = createSendUdp(2000)
let lastMsg = null
const server = Hapi.server({
port: 3000,
// host: 'localhost'
});
server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return 'UDP Forwarding Service';
}
});
server.route({
method: 'GET',
path: '/last',
handler: (request, h) => {
return lastMsg;
}
});
server.route({
method: 'POST',
path: '/',
handler: (request, h) => {
if (_.isObject(request.payload)) {
lastMsg = { ...request.payload }
if (lastMsg.udp) {
sendUdp(lastMsg)
}
}
return {ok: true};
}
});
await server.start();
console.log('Server running on %s', server.info.uri);
};
process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});
init();