Merge pull request #16 from Patreon/jrsun-cluster-support

use express-cluster for drop-in cluster support
This commit is contained in:
Joshua Hull 2017-05-04 15:27:53 -07:00 committed by GitHub
commit 8e7aef421a
3 changed files with 16 additions and 5 deletions

View File

@ -20,6 +20,7 @@
"canvas": "^1.6.2",
"chance": "^1.0.4",
"express": "^4.14.0",
"express-cluster": "0.0.4",
"newrelic": "^1.35.1",
"node-gyp": "^3.4.0",
"sanitize-filename": "^1.6.1",

13
run.js Normal file
View File

@ -0,0 +1,13 @@
const cluster = require('express-cluster');
const app = require('./server.js');
const activePort = process.env.PORT || 3000;
cluster((worker) => {
app.listen(activePort, () => {
console.log('worker ' + worker.id + ' is listening on port ' + activePort);
});
}, {
'respawn': true, // workers will restart on failure
'verbose': true, // logs what happens to console
});

View File

@ -20,9 +20,8 @@ function composeImage(width, height, seed) {
return canvas;
};
const app = express();
const cacheTimeout = 60 * 60 * 24 * 30;
const app = express();
app.get('/healthcheck', (req, res) => {
res.status(200).end();
@ -40,6 +39,4 @@ app.get('/:width/:seed', (req, res) => {
res.end(buffer, 'binary');
});
app.listen(process.env.PORT || 3000, () => {
console.log('listening on http://localhost:3000');
});
module.exports = app;