Ошибка типа: res.json не является функцией на github с Hapijs

#node.js #fetch #hapijs #hapi #node-fetch

Вопрос:

Я пытаюсь создать простое приложение для аутентификации с помощью github(логин). После создания сервера и добавления wating для получения access_token с github я столкнулся с ошибкой.Я использую фреймворк nodejs Hapi

 TypeError: res.json is not a function
 

server.js

 server.route({
    method: "GET",
    path: "/",
    handler: (request, h) => {
      return "<h1>Node Assignement Project</h1>";
    },
  });

  // Login
  server.route({
    method: "GET",
    path: "/login/oauth/authorize",
    handler: (request, h) => {
      return h.redirect(
        `https://github.com/login/oauth/authorize?client_id=${client_id}amp;redirect_uri=http://localhost:5000/login/github/callback`
      );
    },
  });

  async function getUserToken(code) {
    const res = await fetch("https://github.com/login/oauth/access_token", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        client_id,
        client_secret,
        code,
      }),
    });
    const data = res.text();
    const params = new URLSearchParams(data);
    return params.get("access_token");
  }
  // callback
  server.route({
    method: "GET",
    path: "/login/github/callback",
    async handler(request, res) {
      const code = request.query.code;
      const token = await getUserToken(code);
      res.json({ token });
    },
  });
  await server.start();
  console.log("Server on port 5000");
};