forked from spmurrayzzz/wontmerge.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
30 lines (24 loc) · 895 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var express = require('express'),
app = express(),
fs = require('fs'),
mustacheExpress = require('mustache-express'),
sizeOf = require('image-size'),
assetsPath = __dirname + '/assets',
images;
app.engine('mustache', mustacheExpress());
app.set('view engine', 'mustache');
app.set('views', __dirname + '/templates');
app.use('/assets', express.static(assetsPath));
images = fs.readdirSync(assetsPath + '/img');
app.get('/', function(req, res){
var rand = Math.round(Math.random() * (images.length - 1)),
randomImg = images[rand],
size = sizeOf(assetsPath + '/img/' + randomImg);
res.render('index.mustache', { image: randomImg, size: size });
});
app.get('/embed', function(req, res){
var rand = Math.round(Math.random() * (images.length - 1)),
randomImg = images[rand];
res.redirect('/assets/img/' + randomImg);
});
app.listen(process.env.PORT || 3000);