Put configurations in a .env file (Closes #7)pull/24/head
@ -1,8 +0,0 @@ | |||
{ | |||
"port": 7000, | |||
"sessionSecret": "superDuperSecret for session stuff", | |||
"user": "github-user-used-with-api-account", | |||
"clientID": "github client id", | |||
"clientSecret": "clientSecret" | |||
} |
@ -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; | |||
} | |||
}; |
@ -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,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; |
@ -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}!`)); |