mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-27 15:07:42 +00:00
fix: Roll back multithreading
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
070c471a7e
commit
042301995d
1 changed files with 4 additions and 19 deletions
23
server.js
23
server.js
|
|
@ -10,8 +10,6 @@ const minify = require('express-minify');
|
||||||
const postcssMiddleware = require('postcss-middleware');
|
const postcssMiddleware = require('postcss-middleware');
|
||||||
const tmpdir = require('os').tmpdir();
|
const tmpdir = require('os').tmpdir();
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const cluster = require('cluster');
|
|
||||||
const numCPUs = require('os').cpus().length;
|
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
var PORT = process.env.PORT || 8080;
|
var PORT = process.env.PORT || 8080;
|
||||||
|
|
@ -62,20 +60,7 @@ app.use(require('./middleware/load-options'));
|
||||||
app.post('/', require('./routes/post'));
|
app.post('/', require('./routes/post'));
|
||||||
app.get('/*', require('./routes/get'));
|
app.get('/*', require('./routes/get'));
|
||||||
|
|
||||||
// If the current process is the main one
|
// Start listening for HTTP requests
|
||||||
if (cluster.isMaster) {
|
app.listen(PORT, () => {
|
||||||
// Create processes relative to amount of CPUs
|
console.log(`🚀 on http://localhost:${PORT}`);
|
||||||
Array.from({
|
});
|
||||||
length: numCPUs
|
|
||||||
}, () => cluster.fork());
|
|
||||||
|
|
||||||
// When worker closed
|
|
||||||
cluster.on('exit', worker => {
|
|
||||||
console.log(`❌ Worker ${worker.process.pid} died.`);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Start listening for HTTP requests
|
|
||||||
app.listen(PORT, () => {
|
|
||||||
console.log(`🚀 on http://localhost:${PORT}`);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue