Created
January 29, 2019 04:20
-
-
Save 15Dkatz/ca8ce8dbd8dbba7b501860f3d569f019 to your computer and use it in GitHub Desktop.
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 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