Last active
July 15, 2018 11:25
blog-console-web-ui-htmlandconsole
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const hello = require('./src/ansi/animations/hello'); | |
const PORT = process.env.PORT || 3000; | |
const app = express(); | |
// simple hello route | |
app.get('/hello', async (req, res, next) => { | |
const userAgent = req.headers['user-agent']; // checking the useragent | |
const isCommandline = (userAgent.search(/curl|wget/i) !== -1); | |
if (isCommandline) { | |
await res.send(hello.hello()); // This handles the route if | |
return null; // the request came from curl or wget | |
} | |
return next(); // This passes the control to the next matching route handler | |
}); | |
app.use('/hello', express.static('static/hello/index.html')); | |
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment