-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
34 lines (27 loc) · 829 Bytes
/
index.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
const express = require('express');
const util = require('./src/util');
const bye = require('./src/ansi/animations/bye');
const PORT = process.env.PORT || 3000;
const app = express();
// bye bye example
app.get('/', async (req, res, next) => {
const userAgent = req.headers['user-agent'];
if (util.isCommandline(userAgent)) {
const stream = util.getStream(req, res);
await bye(stream);
return null;
}
return next();
});
app.use('/', express.static('static/bye'));
app.use('*', (req, res) => {
const userAgent = req.headers['user-agent'];
if (util.isCommandline(userAgent)) {
return res.send(`
Hit: curl http://byemck.atulr.com/
You are trying to hit an invalid route!
\n`);
}
res.redirect('/');
});
app.listen(PORT, () => console.log(`bye bye app listening on port ${PORT}!`));