-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
54 lines (49 loc) · 1.18 KB
/
routes.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
const wonderq = require('./lib/wonderq')
module.exports = function(app) {
app.post('/messages', function(req, res) {
// Adds a new message to the queue and returns the MessageID
wonderq.sendMessage(
req.body.message
, (err, message_id) => {
if (err !== undefined) {
return res.status(400).json({
status: 'error',
error: err
});
}
return res.status(200).json({
status: 'success',
message_id: message_id
});
});
});
app.get('/messages', function(req, res) {
// Allows a consumer to pull a message from the queue
wonderq.receiveMessage((err, message) => {
if (err !== undefined) {
return res.status(400).json({
status: 'error',
error: err
});
}
return res.status(200).json({
status: 'success',
message: message
});
});
});
app.delete('/messages/:receiptHandle', (req, res) => {
// Deletes the message with a specific receiptHandle from the queue
wonderq.deleteMessage(req.params.receiptHandle, (err, success) => {
if (err !== undefined) {
return res.status(400).json({
status: 'error',
error: err
});
}
return res.status(200).json({
status: 'success'
});
});
});
}