-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (36 loc) · 958 Bytes
/
app.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
/**
* PLAY Notification
*
* Copyright(c) 2012 Christophe Hamerling <[email protected]>
* MIT Licensed
*/
var express = require('express');
var app = express();
var count = 0;
var port = process.env.PORT || 3000;
var path = process.env.SUBCRIBER || '/subscriber'
// JSON
//app.use(express.bodyParser());
// Get body as String, will works in all cases...
app.use (function(req, res, next) {
var data='';
req.setEncoding('utf8');
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {
req.body = data;
next();
});
});
app.get('/', function(req, res){
res.json({ requests : count, info : 'HTTP POST on ' + path} );
});
app.post(path, function(req, res) {
console.log('Got a notification at', new Date().toGMTString());
count++;
console.log(req.body)
});
app.listen(port, function(err) {
console.log('Notification listener is waiting messages on http://localhost:' + port + path);
});