Skip to content

Instantly share code, notes, and snippets.

@15Dkatz
Created January 29, 2019 04:20
Show Gist options
  • Save 15Dkatz/ca8ce8dbd8dbba7b501860f3d569f019 to your computer and use it in GitHub Desktop.
Save 15Dkatz/ca8ce8dbd8dbba7b501860f3d569f019 to your computer and use it in GitHub Desktop.
const express = require('express');
const request = require('request');
const app = express();
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
app.get('/jokes/random', (req, res) => {
request(
{ url: 'https://joke-api-strict-cors.appspot.com/jokes/random' },
(error, response, body) => {
if (error || response.statusCode !== 200) {
return res.status(500).json({ type: 'error', message: err.message });
}
res.json(JSON.parse(body));
}
)
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`listening on ${PORT}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment