Skip to content

Instantly share code, notes, and snippets.

@skippednote
Created September 18, 2017 14:32
Show Gist options
  • Save skippednote/6e22b6b7fb029e1e527ed36247c1c3fc to your computer and use it in GitHub Desktop.
Save skippednote/6e22b6b7fb029e1e527ed36247c1c3fc to your computer and use it in GitHub Desktop.
require('isomorphic-fetch')
const api = (query) => {
return fetch(`https://reddit.com/r/${query}.json`)
.then(res => res.json())
.then(data => {
return data.data.children.reduce((acc, i) => {
acc += `<li>${i.data.title}</li>`
return acc;
}, `<ul>`)
})
.catch(err => console.error(err))
}
module.exports = api;
const express = require('express')
const api = require('./api')
const app = express()
app.use(express.static('public'))
const contentHeader = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Streaming Content</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
`
const contentFooter = `
</body>
</html>
`
app.get('/', async (req, res) => {
const body = await api('javascript')
const html = contentHeader + body + contentFooter
res.send(html)
})
app.listen(8080, () => {
console.log('Listening on port 8080')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment