-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
36 lines (28 loc) · 907 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
31
32
33
34
35
36
'use strict';
var connect = require('connect'),
path = require('path'),
fs = require('fs'),
app = connect(),
backgrounds = [];
fs.readdirSync(path.join(__dirname, 'backgrounds')).forEach(filename => {
if (path.extname(filename) === '.jpg') {
backgrounds.push(filename);
}
})
app.use("/background.jpg", (req, res, next) => {
var filename = path.join(__dirname, 'backgrounds', backgrounds[Math.floor(Math.random() * backgrounds.length)]);
var stat = fs.statSync(filename);
res.writeHead(200, {
'Content-Type': 'image/jpeg',
'Content-Length': stat.size
});
fs.createReadStream(filename).pipe(res);
});
app.use('/', (req, res, next) => {
res.writeHead(301, {Location: "https://chrome.google.com/webstore/detail/departr/beekbnifjppmocjpomjikcplglmfgehe"});
res.end()
});
app.use((err, req, res, next) => {
console.log(err);
});
module.exports = app;