From 674dda1ecf2a426556d2c358bc55e3ce75e7e220 Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 16:30:18 -0500 Subject: [PATCH 1/7] Reformatted index.js --- routes/index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/routes/index.js b/routes/index.js index e1bff90..4e8bd6d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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; \ No newline at end of file From 19be97c4f588f02e905e1358d0b0eec3bd93cdfa Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 16:42:20 -0500 Subject: [PATCH 2/7] Add dotenv to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index ac33ef1..f021d3b 100644 --- a/package.json +++ b/package.json @@ -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", From 3c74fe573499f19cc24ef821f7e8269359a8e29d Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 16:43:03 -0500 Subject: [PATCH 3/7] Implement dotenv and fixed express deprecation errors --- routes/api.js | 17 +++-------------- server.js | 29 ++++++++++------------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/routes/api.js b/routes/api.js index d1c038c..6fba983 100644 --- a/routes/api.js +++ b/routes/api.js @@ -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) diff --git a/server.js b/server.js index 0dc6057..b99e1e7 100644 --- a/server.js +++ b/server.js @@ -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()}!`) -); \ No newline at end of file +app.listen(process.env.PORT, () => console.log(`App listening on port ${process.env.PORT}!`)); \ No newline at end of file From 10effd6887b722d8fe6a4fdb93602edeff2a7657 Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 16:45:59 -0500 Subject: [PATCH 4/7] Removed old config files --- conf.json | 8 -------- configManager.js | 37 ------------------------------------- 2 files changed, 45 deletions(-) delete mode 100644 conf.json delete mode 100644 configManager.js diff --git a/conf.json b/conf.json deleted file mode 100644 index 5b3c852..0000000 --- a/conf.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "port": 7000, - "sessionSecret": "superDuperSecret for session stuff", - - "user": "github-user-used-with-api-account", - "clientID": "github client id", - "clientSecret": "clientSecret" -} \ No newline at end of file diff --git a/configManager.js b/configManager.js deleted file mode 100644 index 8c48aa9..0000000 --- a/configManager.js +++ /dev/null @@ -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; - } - }; \ No newline at end of file From 9258bfdf13580764d0b24b8d5b9bfe915e95cad7 Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 16:47:46 -0500 Subject: [PATCH 5/7] Removed fileIO.js --- fileIO.js | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 fileIO.js diff --git a/fileIO.js b/fileIO.js deleted file mode 100644 index 85a9668..0000000 --- a/fileIO.js +++ /dev/null @@ -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'); - } - }; From 5004c78ee651ff34aad60dc5bb200f05eb4ee1bc Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 16:54:05 -0500 Subject: [PATCH 6/7] Updated .gitingore and Readme.md for using .env --- .gitignore | 1 + README.md | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 812bc3b..f965bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /node_modules/.bin /node_modules /package-lock.json +.env \ No newline at end of file diff --git a/README.md b/README.md index 77b9cb2..b9ec3f2 100644 --- a/README.md +++ b/README.md @@ -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 = +CLIENT_SECRET = +SESSION_SECRET = +PORT = +``` ```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. \ No newline at end of file +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. \ No newline at end of file From ba274af5fb9d083f1deeba06c2963485e7c4e355 Mon Sep 17 00:00:00 2001 From: Peter Morgan Date: Mon, 23 Dec 2019 18:11:56 -0500 Subject: [PATCH 7/7] Updated readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b9ec3f2..5282733 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,10 @@ If you are lucky, you can find the site live [here](https://github-graphs.com/); Create a .env file with the code below filled in. ``` -CLIENT_ID = -CLIENT_SECRET = -SESSION_SECRET = -PORT = +CLIENT_ID = +CLIENT_SECRET = +SESSION_SECRET = +PORT = ``` ```bash