mirror of
				https://git.sleeping.town/mirrors/foxy-moxy
				synced 2025-11-03 18:12:17 -08:00 
			
		
		
		
	Merge pull request #16 from Patreon/jrsun-cluster-support
use express-cluster for drop-in cluster support
This commit is contained in:
		
						commit
						8e7aef421a
					
				
					 3 changed files with 16 additions and 5 deletions
				
			
		| 
						 | 
					@ -20,6 +20,7 @@
 | 
				
			||||||
    "canvas": "^1.6.2",
 | 
					    "canvas": "^1.6.2",
 | 
				
			||||||
    "chance": "^1.0.4",
 | 
					    "chance": "^1.0.4",
 | 
				
			||||||
    "express": "^4.14.0",
 | 
					    "express": "^4.14.0",
 | 
				
			||||||
 | 
					    "express-cluster": "0.0.4",
 | 
				
			||||||
    "newrelic": "^1.35.1",
 | 
					    "newrelic": "^1.35.1",
 | 
				
			||||||
    "node-gyp": "^3.4.0",
 | 
					    "node-gyp": "^3.4.0",
 | 
				
			||||||
    "sanitize-filename": "^1.6.1",
 | 
					    "sanitize-filename": "^1.6.1",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								run.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								run.js
									
										
									
									
									
										Normal 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
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					@ -20,9 +20,8 @@ function composeImage(width, height, seed) {
 | 
				
			||||||
    return canvas;
 | 
					    return canvas;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const cacheTimeout = 60 * 60 * 24 * 30;
 | 
					const cacheTimeout = 60 * 60 * 24 * 30;
 | 
				
			||||||
 | 
					const app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.get('/healthcheck', (req, res) => {
 | 
					app.get('/healthcheck', (req, res) => {
 | 
				
			||||||
    res.status(200).end();
 | 
					    res.status(200).end();
 | 
				
			||||||
| 
						 | 
					@ -40,6 +39,4 @@ app.get('/:width/:seed', (req, res) => {
 | 
				
			||||||
    res.end(buffer, 'binary');
 | 
					    res.end(buffer, 'binary');
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.listen(process.env.PORT || 3000, () => {
 | 
					module.exports = app;
 | 
				
			||||||
    console.log('listening on http://localhost:3000');
 | 
					 | 
				
			||||||
});
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue