factor our cluster into run.js

This commit is contained in:
Jeffrey Sun 2017-05-03 16:06:47 -07:00
parent f5712fef77
commit a5b32e9d53
2 changed files with 29 additions and 26 deletions

13
run.js Normal file
View file

@ -0,0 +1,13 @@
const cluster = require('express-cluster');
const app = require('./server.js');
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

@ -5,7 +5,6 @@ try {
} }
const express = require('express'); const express = require('express');
const cluster = require('express-cluster');
const uuid = require('uuid/v4'); const uuid = require('uuid/v4');
const sanitize = require('sanitize-filename'); const sanitize = require('sanitize-filename');
const Canvas = require('canvas'); const Canvas = require('canvas');
@ -22,8 +21,6 @@ function composeImage(width, height, seed) {
}; };
const cacheTimeout = 60 * 60 * 24 * 30; const cacheTimeout = 60 * 60 * 24 * 30;
cluster((worker) => {
const app = express(); const app = express();
app.get('/healthcheck', (req, res) => { app.get('/healthcheck', (req, res) => {
@ -42,11 +39,4 @@ cluster((worker) => {
res.end(buffer, 'binary'); res.end(buffer, 'binary');
}); });
activePort = process.env.PORT || 3000; module.exports = app;
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
})