How do I assign a variable from the HTTP response body of an HTTP request? I tried doing it like this, but it's getting a 502 error.
const https = require('https')
const getDadJokes = async (request, h) => {
const dadJokesApi = {
hostname: 'icanhazdadjoke.com',
method: 'GET',
path: '/',
headers: {
'Accept': 'text/plain',
},
}
const dadJokes = https.request(dadJokesApi, (res) => {
res.on('data', (body) => body);
});
dadJokes.end();
const response = h.response(dadJokes);
return response;
};