Website for visualizing a persons github network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

  1. const routes = require('express').Router();
  2. const got = require("got");
  3. const GITHUB_API = "https://api.github.com";
  4. const configLoader = require('../configManager');
  5. const authenticate = "?client_id=" + configLoader.getClientID() +
  6. "&client_secret=" + configLoader.getClientSecret();
  7. function queryGitHubAPI(requestURL)
  8. {
  9. return new Promise(function(reject, resolve)
  10. {
  11. const queryRUL = GITHUB_API + requestURL + authenticate;
  12. got(queryRUL, { json: true }).then(response =>
  13. {
  14. resolve(response.body);
  15. }).catch(error =>
  16. {
  17. resolve(response.body)
  18. });
  19. })
  20. }
  21. //https://api.github.com/users/whatever?client_id=xxxx&client_secret=yyyy
  22. // function authenticateWithGitHub()
  23. // {
  24. // const authURL = GITHUB_API + "/users/" + configLoader.getAPIUser() + "?client_id=" + configLoader.getClientID() +
  25. // "&client_secret=" + configLoader.getClientSecret();
  26. //
  27. // return new Promise(function(resolve, reject)
  28. // {
  29. // got(authURL, { json: true }).then(response =>
  30. // {
  31. // console.log(response);
  32. // resolve(response);
  33. // }).catch(error => {
  34. // reject(error);
  35. // console.log(error.response.body);
  36. // });
  37. // })
  38. //
  39. // }
  40. routes.get('/*', (request, result) =>
  41. {
  42. const gitHubAPIURL = request.url;
  43. queryGitHubAPI(gitHubAPIURL).then(function(data)
  44. {
  45. result.write(JSON.stringify(data));
  46. result.end();
  47. }).catch(function(error)
  48. {
  49. result.write(JSON.stringify(error));
  50. result.end();
  51. })
  52. });
  53. module.exports = routes;