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..5282733 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 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 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'); - } - }; 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", 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/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 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