mirror of
https://git.sleeping.town/mirrors/foxy-moxy
synced 2024-11-23 12:37:43 +00:00
Make the server just return the image.
This commit is contained in:
parent
2ba7f83b98
commit
0e2d3258ab
1 changed files with 6 additions and 7 deletions
13
server.js
13
server.js
|
@ -42,25 +42,24 @@ var app = express();
|
||||||
app.use(express.static(__dirname + '/images'));
|
app.use(express.static(__dirname + '/images'));
|
||||||
|
|
||||||
app.get('/', function(req, res) {
|
app.get('/', function(req, res) {
|
||||||
var fileNames = writeFoxesToDisk(200, 200, 28);
|
var width = 400;
|
||||||
var images = fileNames.map(fileName => '<img src="/' + fileName + '"/>');
|
var seed = uuid();
|
||||||
res.send(images.join(''));
|
var canvas = composeImage(width, width, seed);
|
||||||
|
res.end(canvas.toBuffer(), 'binary');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/:width', function(req, res) {
|
app.get('/:width', function(req, res) {
|
||||||
var width = parseInt(req.params.width) || 400;
|
var width = parseInt(req.params.width) || 400;
|
||||||
var seed = uuid();
|
var seed = uuid();
|
||||||
var canvas = composeImage(width, width, seed);
|
var canvas = composeImage(width, width, seed);
|
||||||
var fileName = writeFoxToDisk(canvas, seed);
|
res.end(canvas.toBuffer(), 'binary');
|
||||||
res.send('<img src="/' + fileName + '"/>');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/:width/:seed', function(req, res) {
|
app.get('/:width/:seed', function(req, res) {
|
||||||
var width = parseInt(req.params.width) || 400;
|
var width = parseInt(req.params.width) || 400;
|
||||||
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 fileName = writeFoxToDisk(canvas, seed);
|
res.end(canvas.toBuffer(), 'binary');
|
||||||
res.send('<img src="/' + fileName + '"/>');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(process.env.PORT || 3000);
|
app.listen(process.env.PORT || 3000);
|
||||||
|
|
Loading…
Reference in a new issue