Skip to content

Instantly share code, notes, and snippets.

@a7ul
Last active July 15, 2018 11:25
Show Gist options
  • Save a7ul/106bab31bfe31cbb348ffca10805e87f to your computer and use it in GitHub Desktop.
Save a7ul/106bab31bfe31cbb348ffca10805e87f to your computer and use it in GitHub Desktop.
blog-console-web-ui-htmlandconsole
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