1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | app.post('/signals', signal.processSignal); exports.processSignal = function(req, res) { var signal = req.body; console.log('Processing Signal:' + JSON.stringify(signal)); mongo.Db.connect(mongoUri, function (err, db) { db.collection('subscriptions', function(err, collection) { collection.find().toArray(function(err, items) { matches = _.filter(items, function(sub){return sub.eventTitle == signal.eventTitle}); _.each(matches, function (sub) {processMatch(sub, signal)}); res.send(matches); }); }); }); |
1 2 3 4 5 6 7 8 9 10 | function processMatch(subscription, signal) { opts = { from:'Simple Notification Service', to: subscription.alertEndpoint, subject: subscription.eventTitle + ' happened at:' + new Date(), body: signal.instancedata } // Send alert mailer.sendMail(opts); } |
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 | exports.sendMail = function (opts) { var mailOpts, smtpTransport; console.log ('Creating Transport'); smtpTransport = nodemailer.createTransport('SMTP', { service:'Gmail', auth:{ user: config.email, pass: config.password } }); // mailing options mailOpts = { from: opts.from, replyTo: opts.from, to: opts.to, subject: opts.subject, html: opts.body }; console.log('mailOpts:', mailOpts); console.log('Sending Mail'); // Send mail smtpTransport.sendMail(mailOpts, function (error, response) { if (error) { console.log(error); }else { console.log('Message sent:' + response.message); } console.log('Closing Transport'); smtpTransport.close(); }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 | it('should verify revised News flash 6 event', function(done) { request(url) .get('/events/'+ newsFlash6id) .end(function(err, res) { if (err) { throw err; } res.should.have.status(200); res.body.should.have.property('title'); res.body.title.should.equal('News flash 6 - revised'); done(); }); }); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |