-
Hey guys, I'm writing an API route that will call GitHub API and return my user with GitHub's response. My API is essentially a proxy. However, my server in the terminal is crashing with const https = require('https')
export default (req, res) => {
const options = {
host: 'api.github.com',
path: '/search/repositories?q=tetris',
headers: {'user-agent': 'gohyifan'}
}
https.get(options, (ghRes) => {
ghRes.on('data', (d) => {
res.json(d);
});
}).on('error', (e) => {
console.error(e);
});
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I did it with axios and it worked. Thread can be closed. const axios = require('axios');
async function handler(req, res) {
const response = await axios.get('https://api.github.com/search/repositories?q=tetris');
if (response) {
res.json(response.data);
} else {
res.json({});
}
}
export default handler; |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
I did it with axios and it worked. Thread can be closed.