在Next.js API路由中进行外部API调用时遇到错误

I'm writing an API route in next.js 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 Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. What am I doing wrong? Appreciate your help, thanks!

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);
  });
}