Browse Source

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

pull/33/head
jrtechs 6 years ago
parent
commit
1c787b6498
7 changed files with 90 additions and 28 deletions
  1. +1
    -1
      blogContent/posts/programming/media/CSTHEORY/PDAConstruction.svg
  2. +10
    -0
      config.json
  3. +17
    -18
      server.js
  4. +33
    -0
      utils/configLoader.js
  5. +1
    -1
      utils/renderBlogPost.js
  6. +17
    -8
      utils/sql.js
  7. +11
    -0
      utils/utils.js

+ 1
- 1
blogContent/posts/programming/media/CSTHEORY/PDAConstruction.svg
File diff suppressed because it is too large
View File


+ 10
- 0
config.json View File

@ -0,0 +1,10 @@
{
"PORT": 8000,
"SESSION_SECRET": "random-data-to-seed-session-data",
"SQL_HOST": "sql-hostname",
"SQL_DATABASE": "sql-database-name",
"SQL_USER": "sql-user",
"SQL_PASSWORD": "sql-password"
}

+ 17
- 18
server.js View File

@ -5,40 +5,41 @@
* appropriate pages.
*/
//http server
/** Stores the configuration for the server */
const config = require('./utils/configLoader').getConfig();
/** Port for the server to run on */
const port = config.PORT;
/** http server */
const http = require('http');
//used to parse the request URL
/** used to parse the request URL */
const url = require('url');
//express app
/** express app */
const express = require("express");
//express app
/** express app */
const app = express();
//server side logging
/** server side logging */
const sql = require('./utils/sql');
//Used for gzip compression
/** Used for gzip compression */
const compression = require('compression');
//used for file io
const utils = require('./utils/utils.js');
//Updates the site map whenever the server is started
/**Updates the site map whenever the server is started */
const map = require('./utils/generateSiteMap.js');
map.main();
//port for the server to run on
const port = 8000;
//session data for login
/**session data for login */
const session = require('express-session');
//Initializes sessions for login
app.use(session({ secret: utils.getFileLine('../session_secret'), cookie: { maxAge: 6000000 }}));
/**Initializes sessions for login */
app.use(session({ secret: config.SESSION_SECRET, cookie: { maxAge: 6000000 }}));
const projects = ["/steam/"];
@ -99,6 +100,4 @@ app.use(function(request, result)
app.use(compression());
http.createServer(app).listen(port);
http.createServer(app).listen(port);

+ 33
- 0
utils/configLoader.js View File

@ -0,0 +1,33 @@
const utils = require('../utils/utils');
/**
* @author Jeffery Russell 11-24-18
*
* @type {{main: module.exports.main}}
*/
module.exports=
{
/**
*
* @returns {*|any}
*/
getConfig: function()
{
const configContents = ["PORT", "SESSION_SECRET",
"SQL_HOST", "SQL_DATABASE", "SQL_PASSWORD"];
var config = utils.getFileAsJSON("./config.json");
for(var i = 0; i < configContents.length; i++)
{
if(!config.hasOwnProperty(configContents[i]))
{
console.log("Missing config property: " + configContents[i]);
process.exit(1);
}
}
return config;
}
}

+ 1
- 1
utils/renderBlogPost.js View File

@ -111,7 +111,7 @@ module.exports=
//this line prevents older versions of pandoc from including invalid cdm scripts
result = result.split("<script src=\"https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML-full\" type=\"text/javascript\"></script>").join("");
result = result.split("<script src=\"https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\" type=\"text/javascript\"></script>").join("");
if(blocks == -1)
resolve(result);

+ 17
- 8
utils/sql.js View File

@ -1,23 +1,32 @@
/**
* Boated file which handles all the SQL
* queries ran by the server
*
* @author Jeffery Russell
*/
const mysql = require('mysql');
/** Sanitizer to clean user inputs and prevent SQL injections */
const sanitizer = require('sanitizer');
const Promise = require('promise');
/** Crypto package used for hashing */
const crypto = require('crypto');
/** Used to parse post data */
const qs = require('querystring');
const utils = require('../utils/utils.js');
/** Used to load the config file from the disk */
const config = require('../utils/configLoader').getConfig();
/** SQL connection */
const con = mysql.createConnection({
host: "localhost",
user: "blog_user",
password: utils.getFileLine('../sql_secret'),
database: "jrtechs_blog"
host: config.SQL_HOST,
user: config.SQL_USER,
password: config.SQL_PASSWORD,
database: config.SQL_DATABASE
});
con.connect(function(err) {
if (err)
console.log(err);

+ 11
- 0
utils/utils.js View File

@ -51,6 +51,17 @@ module.exports=
},
/**
*
* @param fileName
* @returns {any}
*/
getFileAsJSON: function(fileName)
{
return JSON.parse(fs.readFileSync(fileName, 'utf8'));
},
/**
* Returns all the contents of a file as a single line
* with no break lines.

Loading…
Cancel
Save