mirror of
				https://git.sleeping.town/mirrors/foxy-moxy
				synced 2025-11-03 10:02:34 -08:00 
			
		
		
		
	Merge pull request #11 from Patreon/luke---cache-control-headers
Add cache-control headers.
This commit is contained in:
		
						commit
						753f70ead1
					
				
					 1 changed files with 5 additions and 0 deletions
				
			
		| 
						 | 
					@ -41,11 +41,14 @@ var app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.use(express.static(__dirname + '/images'));
 | 
					app.use(express.static(__dirname + '/images'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var cacheTimeout = 60 * 60 * 24 * 30;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.get('/', function(req, res) {
 | 
					app.get('/', function(req, res) {
 | 
				
			||||||
    var width = 400;
 | 
					    var width = 400;
 | 
				
			||||||
    var seed = uuid();
 | 
					    var seed = uuid();
 | 
				
			||||||
    var canvas = composeImage(width, width, seed);
 | 
					    var canvas = composeImage(width, width, seed);
 | 
				
			||||||
    var buffer = canvas.toBuffer();
 | 
					    var buffer = canvas.toBuffer();
 | 
				
			||||||
 | 
					    res.set('Cache-Control', 'max-age=' + cacheTimeout);
 | 
				
			||||||
    res.set('Content-length', buffer.length);
 | 
					    res.set('Content-length', buffer.length);
 | 
				
			||||||
    res.type('png');
 | 
					    res.type('png');
 | 
				
			||||||
    res.end(buffer, 'binary');
 | 
					    res.end(buffer, 'binary');
 | 
				
			||||||
| 
						 | 
					@ -60,6 +63,7 @@ app.get('/:width', function(req, res) {
 | 
				
			||||||
    var seed = uuid();
 | 
					    var seed = uuid();
 | 
				
			||||||
    var canvas = composeImage(width, width, seed);
 | 
					    var canvas = composeImage(width, width, seed);
 | 
				
			||||||
    var buffer = canvas.toBuffer();
 | 
					    var buffer = canvas.toBuffer();
 | 
				
			||||||
 | 
					    res.set('Cache-Control', 'max-age=' + cacheTimeout);
 | 
				
			||||||
    res.set('Content-length', buffer.length);
 | 
					    res.set('Content-length', buffer.length);
 | 
				
			||||||
    res.type('png');
 | 
					    res.type('png');
 | 
				
			||||||
    res.end(buffer, 'binary');
 | 
					    res.end(buffer, 'binary');
 | 
				
			||||||
| 
						 | 
					@ -70,6 +74,7 @@ app.get('/:width/:seed', function(req, res) {
 | 
				
			||||||
    var seed = sanitize(req.params.seed) || uuid();
 | 
					    var seed = sanitize(req.params.seed) || uuid();
 | 
				
			||||||
    var canvas = composeImage(width, width, seed);
 | 
					    var canvas = composeImage(width, width, seed);
 | 
				
			||||||
    var buffer = canvas.toBuffer();
 | 
					    var buffer = canvas.toBuffer();
 | 
				
			||||||
 | 
					    res.set('Cache-Control', 'max-age=' + cacheTimeout);
 | 
				
			||||||
    res.set('Content-length', buffer.length);
 | 
					    res.set('Content-length', buffer.length);
 | 
				
			||||||
    res.type('png');
 | 
					    res.type('png');
 | 
				
			||||||
    res.end(buffer, 'binary');
 | 
					    res.end(buffer, 'binary');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue