This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// exports RabbitMQ connection | |
const MQ = require('./rabbitmq-config'); | |
global.smsWorker = { | |
send: function (message) { | |
// publish message on sms exchange | |
return MQ.publish('sms', message); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pm2Config = { | |
"apps": [ | |
{ | |
"name": "app", | |
"script": "app.js", | |
"exec_mode": "cluster_mode", | |
"instances": "max" | |
}, | |
{ | |
"name": "smsWorker", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.on('message', function(data) { | |
sendSMS(data); // use twilio or something to send sms | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
const numCPUs = require('os').cpus().length; | |
module.exports.create = function (options, callback) { | |
if (cluster.isMaster) { | |
// fork child process for notif/sms/email worker | |
global.smsWorker = require('child_process').fork('./smsWorker'); | |
global.emailWorker = require('child_process').fork('./emailWorker'); | |
global.notifiWorker = require('child_process').fork('./notifWorker'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
const numCPUs = require('os').cpus().length; | |
module.exports.create = function(options, callback){ | |
if (cluster.isMaster) { | |
// fork child process for notif/sms/email worker | |
global.smsWorker = require('child_process').fork('./smsWorker'); | |
global.emailWorker = require('child_process').fork('./emailWorker'); | |
global.notifiWorker = require('child_process').fork('./notifWorker'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cluster = require('cluster'); | |
const numCPUs = require('os').cpus().length; | |
module.exports.create = function(options, callback){ | |
if (cluster.isMaster) { | |
// fork child process for notif/sms/email worker | |
global.smsWorker = require('child_process').fork('./smsWorker'); | |
global.emailWorker = require('child_process').fork('./emailWorker'); | |
global.notifiWorker = require('child_process').fork('./notifWorker'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.submit = function(req, res) { | |
if(req.session.count && req.session.count > 0) { // true | |
//do something | |
res.sendStatus(200); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// name = "my-session" -> base64 value of required object (cookie) | |
// name.sig = "my-session.sig" -> signed value of cookie using Keygrip | |
let cookie = Buffer.from(JSON.stringify({"count":2})).toString('base64'); // base64 converted value of cookie | |
let kg = Keygrip(['testKey']) // same key as I'm using in my app | |
let hash = kg.sign('my-session=' + cookie); | |
await request(app).get('api/image/submit').set("Accept", "text/html") | |
.set('cookie', ['my-session=' + cookie + '; ' + 'my-session.sig=' + hash + ';']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.submit = function(req, res) { | |
if (req.session.count && req.session.count > 0) { // get count from req.session | |
// perform further tasks | |
res.sendStatus(200); | |
} else { | |
res.sendStatus(400); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.create = function(req, res) { | |
// upload image to s3 | |
var photos = PhotosTable.create(req.files.names); // add entries in database | |
req.session.count = photos.length; // set count in req.session | |
res.redirect(`api/image/submit`); | |
} |