Browse Source

Merge branch 'master' of https://github.com/jrtechs/github-graphs

pull/11/head
CetaceanNation 5 years ago
parent
commit
782cef7bd8
6 changed files with 93 additions and 3 deletions
  1. +5
    -0
      configManager.js
  2. +2
    -1
      package.json
  3. +1
    -1
      public/js/githubAPI.js
  4. +66
    -0
      routes/api.js
  5. +17
    -0
      routes/index.js
  6. +2
    -1
      server.js

+ 5
- 0
configManager.js View File

@ -33,6 +33,11 @@ module.exports=
getSessionSecret: function()
{
return config.sessionSecret;
},
getAPIUser: function()
{
return config.user;
}
};

+ 2
- 1
package.json View File

@ -20,6 +20,7 @@
"dependencies": {
"express": "^4.16.4",
"express-session": "^1.15.6",
"fs": "0.0.1-security"
"fs": "0.0.1-security",
"got": "^9.6.0"
}
}

+ 1
- 1
public/js/githubAPI.js View File

@ -7,7 +7,7 @@
*/
const APIROOT = "https://api.github.com";
const APIROOT = "api";
const API_USER_PATH = "/users/";

+ 66
- 0
routes/api.js View File

@ -0,0 +1,66 @@
const routes = require('express').Router();
const got = require("got");
const GITHUB_API = "https://api.github.com";
const configLoader = require('../configManager');
const authenticate = "?client_id=" + configLoader.getClientID() +
"&client_secret=" + configLoader.getClientSecret();
//caching program to make the application run faster
const cache = require('memory-cache');
function queryGitHubAPI(requestURL)
{
const apiData = cache.get(requestURL);
return new Promise(function(reject, resolve)
{
if(apiData == null)
{
const queryRUL = GITHUB_API + requestURL + authenticate;
got(queryRUL, { json: true }).then(response =>
{
resolve(response.body);
cache.put(requestURL, response.body);
}).catch(error =>
{
resolve(response.body);
cache.put(requestURL, response.body);
});
}
else
{
resolve(apiData);
}
})
}
routes.get('/*', (request, result) =>
{
const gitHubAPIURL = request.url;
queryGitHubAPI(gitHubAPIURL).then(function(data)
{
result.write(JSON.stringify(data));
result.end();
}).catch(function(error)
{
result.write(JSON.stringify(error));
result.end();
})
});
module.exports = routes;

+ 17
- 0
routes/index.js View File

@ -0,0 +1,17 @@
const routes = require('express').Router();
const api = require('./api');
routes.use('/api', api);
routes.get("/", (request, result) =>
{
result.redirect("index.html");
});
routes.get('*', (request, result) =>
{
result.redirect("404.html");
});
module.exports = routes;

+ 2
- 1
server.js View File

@ -21,12 +21,13 @@ app.use(express.json());
app.use(express.static('public'));
const routes = require('./routes');
app.use('/', routes);
app.listen(configLoader.getConfiguration().port, () =>
console.log(`App listening on port ${configLoader.getPort()}!`)
);

Loading…
Cancel
Save