mirror of
				https://git.sleeping.town/mirrors/foxy-moxy
				synced 2025-11-03 18:12:17 -08:00 
			
		
		
		
	use express-cluster for drop-in cluster support
This commit is contained in:
		
							parent
							
								
									1a42d9dbc1
								
							
						
					
					
						commit
						7c34463cc4
					
				
					 2 changed files with 24 additions and 19 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",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								server.js
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								server.js
									
										
									
									
									
								
							| 
						 | 
					@ -5,6 +5,7 @@ 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');
 | 
				
			||||||
| 
						 | 
					@ -20,10 +21,11 @@ function composeImage(width, height, seed) {
 | 
				
			||||||
    return canvas;
 | 
					    return canvas;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const cacheTimeout = 60 * 60 * 24 * 30;
 | 
					const cacheTimeout = 60 * 60 * 24 * 30;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cluster((worker) => {
 | 
				
			||||||
 | 
					    const app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    app.get('/healthcheck', (req, res) => {
 | 
					    app.get('/healthcheck', (req, res) => {
 | 
				
			||||||
        res.status(200).end();
 | 
					        res.status(200).end();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
| 
						 | 
					@ -40,6 +42,8 @@ app.get('/:width/:seed', (req, res) => {
 | 
				
			||||||
        res.end(buffer, 'binary');
 | 
					        res.end(buffer, 'binary');
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.listen(process.env.PORT || 3000, () => {
 | 
					    activePort = process.env.PORT || 3000;
 | 
				
			||||||
    console.log('listening on http://localhost:3000');
 | 
					    app.listen(activePort, () => {
 | 
				
			||||||
 | 
					        console.log('worker ' + worker.id + ' is listening on port ' + activePort);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue