Browse Source

Merge pull request #18 from PeterMorganGH/master

Put configurations in a .env file (Closes #7)
pull/24/head
Jeffery Russell 4 years ago
committed by GitHub
parent
commit
7322a2b98d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 127 deletions
  1. +1
    -0
      .gitignore
  2. +11
    -9
      README.md
  3. +0
    -8
      conf.json
  4. +0
    -37
      configManager.js
  5. +0
    -32
      fileIO.js
  6. +1
    -0
      package.json
  7. +3
    -14
      routes/api.js
  8. +4
    -8
      routes/index.js
  9. +10
    -19
      server.js

+ 1
- 0
.gitignore View File

@ -6,3 +6,4 @@
/node_modules/.bin
/node_modules
/package-lock.json
.env

+ 11
- 9
README.md View File

@ -4,13 +4,12 @@ Website for visualizing a persons github network.
![Example Graph](./doc/graphExample.png)
If you are lucky, you can find the site live
[here](https://github-graphs.com/);
If you are lucky, you can find the site live [here](https://github-graphs.com/);
# Built With
- [BootStrap](https://getbootstrap.com/) CSS Framework
- [BootStrap](https://getbootstrap.com/)
- [jQuery](https://jquery.com/)
- [Vis JS](http://visjs.org/)
- [Github v3 API](https://developer.github.com/v3/)
@ -21,8 +20,14 @@ If you are lucky, you can find the site live
# Running
Update your conf.json file to contain your preferred port and github
api credentials.
Create a .env file with the code below filled in.
```
CLIENT_ID = <your_github_username>
CLIENT_SECRET = <your_generated_personal_access>
SESSION_SECRET = <any_string_you_want>
PORT = <any_number>
```
```bash
npm install
@ -35,7 +40,4 @@ node server.js
# Contributing
If you want to contribute to this project and don't know where to start,
look at the open issues. Once you know what you want to work on,
just discuss it in the issues and file a pull request. We are very open
to new contributes.
We are very open to new contributors. If you want to contribute to this project, and don't know where to start, look at the [open issues](https://github.com/jrtechs/github-graphs/issues). Once you know what you want to work on, comment on the issue and file a pull request.

+ 0
- 8
conf.json View File

@ -1,8 +0,0 @@
{
"port": 7000,
"sessionSecret": "superDuperSecret for session stuff",
"user": "github-user-used-with-api-account",
"clientID": "github client id",
"clientSecret": "clientSecret"
}

+ 0
- 37
configManager.js View File

@ -1,37 +0,0 @@
const fileIO = require('./fileIO');
const CONFIG_FILE_NAME = "conf.json";
const config = fileIO.getFileAsJSON(CONFIG_FILE_NAME);
module.exports=
{
getConfiguration: function()
{
return config;
},
syncToDisk: function()
{
fileIO.writeJSONToFile(CONFIG_FILE_NAME, config);
},
getPort: function()
{
return config.port;
},
getClientID: function()
{
return config.clientID;
},
getClientSecret: function()
{
return config.clientSecret;
},
getSessionSecret: function()
{
return config.sessionSecret;
}
};

+ 0
- 32
fileIO.js View File

@ -1,32 +0,0 @@
/** Used to read and write files from disk */
const fs = require('fs');
module.exports =
{
writeJSONToFile: function(fileName, jsonObject)
{
const json = JSON.stringify(jsonObject, null, 4);
fs.writeFile(fileName, json, 'utf8', function()
{
console.log("Wrote to " + fileName);
});
},
/**
*
* @param fileName
* @returns {any}
*/
getFileAsJSON: function(fileName)
{
return JSON.parse(module.exports.getFile(fileName));
},
getFile: function(filename)
{
return fs.readFileSync(filename, 'utf8');
}
};

+ 1
- 0
package.json View File

@ -18,6 +18,7 @@
},
"homepage": "https://github.com/jrtechs/github-graphs#readme",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.16.4",
"express-session": "^1.15.6",
"fs": "0.0.1-security",

+ 3
- 14
routes/api.js View File

@ -1,20 +1,9 @@
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');
const dotenv = require("dotenv").config();
const GITHUB_API = "https://api.github.com";
const authenticate = `client_id=${process.env.CLIENT_ID}&client_secret=${process.env.CLIENT_SECRET}`;
function queryGitHubAPI(requestURL)

+ 4
- 8
routes/index.js View File

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

+ 10
- 19
server.js View File

@ -1,30 +1,21 @@
/** express app for routing */
const express = require("express");
/**session data for login and storing preferences*/
const session = require('express-session');
const configLoader = require('./configManager.js');
const dotenv = require("dotenv").config();
const app = express();
/**Initializes sessions for login */
app.use(session(
{ secret: configLoader.getSessionSecret(),
cookie: { maxAge: 6000000 }}
));
app.use(express.urlencoded()); //for easy retrieval of post and get data
const sessionProperties = {
secret: process.env.SESSION_SECRET,
cookie: { maxAge: 6000000 },
resave: false,
saveUninitialized: false
};
app.use(session(sessionProperties));
app.use(express.urlencoded({ extended: true }));
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()}!`)
);
app.listen(process.env.PORT, () => console.log(`App listening on port ${process.env.PORT}!`));

Loading…
Cancel
Save