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.

66 lines
1.5 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. //caching program to make the application run faster
  8. const cache = require('memory-cache');
  9. function queryGitHubAPI(requestURL)
  10. {
  11. const apiData = cache.get(requestURL);
  12. return new Promise(function(reject, resolve)
  13. {
  14. if(apiData == null)
  15. {
  16. const queryRUL = GITHUB_API + requestURL + authenticate;
  17. got(queryRUL, { json: true }).then(response =>
  18. {
  19. resolve(response.body);
  20. cache.put(requestURL, response.body);
  21. }).catch(error =>
  22. {
  23. // resolve(response.body);
  24. // cache.put(requestURL, response.body);
  25. console.log(error);
  26. reject(error);
  27. });
  28. }
  29. else
  30. {
  31. resolve(apiData);
  32. }
  33. })
  34. }
  35. routes.get('/*', (request, result) =>
  36. {
  37. const gitHubAPIURL = request.url;
  38. result.setHeader('Content-Type', 'application/json');
  39. queryGitHubAPI(gitHubAPIURL).then(function(data)
  40. {
  41. result.write(JSON.stringify(data));
  42. result.end();
  43. }).catch(function(error)
  44. {
  45. result.write(JSON.stringify(error));
  46. result.end();
  47. })
  48. });
  49. module.exports = routes;