mirror of
https://git.sleeping.town/mirrors/foxy-moxy
synced 2024-11-21 19:47:43 +00:00
factor our cluster into run.js
This commit is contained in:
parent
f5712fef77
commit
a5b32e9d53
2 changed files with 29 additions and 26 deletions
13
run.js
Normal file
13
run.js
Normal 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
|
||||
});
|
12
server.js
12
server.js
|
@ -5,7 +5,6 @@ try {
|
|||
}
|
||||
|
||||
const express = require('express');
|
||||
const cluster = require('express-cluster');
|
||||
const uuid = require('uuid/v4');
|
||||
const sanitize = require('sanitize-filename');
|
||||
const Canvas = require('canvas');
|
||||
|
@ -22,8 +21,6 @@ function composeImage(width, height, seed) {
|
|||
};
|
||||
|
||||
const cacheTimeout = 60 * 60 * 24 * 30;
|
||||
|
||||
cluster((worker) => {
|
||||
const app = express();
|
||||
|
||||
app.get('/healthcheck', (req, res) => {
|
||||
|
@ -42,11 +39,4 @@ cluster((worker) => {
|
|||
res.end(buffer, 'binary');
|
||||
});
|
||||
|
||||
activePort = process.env.PORT || 3000;
|
||||
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
|
||||
})
|
||||
module.exports = app;
|
||||
|
|
Loading…
Reference in a new issue