-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
42 lines (37 loc) · 759 Bytes
/
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
'use strict';
const got = require('got');
const fastify = require('fastify');
const server = fastify({
logger: false
});
server.get('/', (request, reply) => {
reply.send({
msg: 'Main server'
});
});
server.post('/webhook', (request, reply) => {
got.post('http://127.0.0.1:8000/callback', {
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
msg: `${request.body.name} has been sent from server`
})
}).then(_ => {
reply.send({
status: 'success',
msg: `User ${request.body.name} inserted`
});
}).catch(err => {
reply.send({
status: 'error',
msg: JSON.stringify(err)
});
});
});
server.listen(3000, '127.0.0.1', err => {
if (err) {
throw err;
}
console.log('server running on 3000');
});