diff --git a/README.md b/README.md index cc0d784..2d9bbd6 100644 --- a/README.md +++ b/README.md @@ -54,4 +54,5 @@ npm install markdown npm install markdown-to-html -g npm install highlight npm install crypto +npm i express-force-ssl ``` diff --git a/includes/footer.html b/includes/footer.html index 21141a7..4482490 100644 --- a/includes/footer.html +++ b/includes/footer.html @@ -18,10 +18,10 @@ -
Copyright © Jrtechs.net 2018
+
Copyright © Jrtechs.net 2018
- + diff --git a/posts/category.js b/posts/category.js index 269e7d3..7909e31 100644 --- a/posts/category.js +++ b/posts/category.js @@ -16,8 +16,6 @@ var renderPosts = function(result, resultURL) sql.getPostsFromCategory(splitURL[2]).then(function(posts) { var promises = []; - console.log(posts); - console.log("^^^^"); posts.forEach(function(p) { promises.push(new Promise(function(res, rej) diff --git a/posts/singlePost.js b/posts/singlePost.js index 9fe10d5..c940583 100644 --- a/posts/singlePost.js +++ b/posts/singlePost.js @@ -4,6 +4,8 @@ var Promise = require('promise'); var markdown = require( "markdown" ).markdown; +const sql = require('../utils/sql'); + module.exports= { @@ -20,7 +22,10 @@ module.exports= { res.write("
"); //image - res.write("\"Nature\""); + if(!(post.picture_url ==="n/a")) + { + res.write("\"Nature\""); + } res.write("
"); //title @@ -31,23 +36,29 @@ module.exports= res.write("
"); - var pathName = "entries/" + post.url + ".md"; try { - var html = markdown.toHTML(utils.getFileContents(pathName).toString()); + sql.getCategory(post.category_id).then(function(category) + { + var pathName = "entries/" + category.url + "/" + post.url + ".md"; - html = html.split("").join("
");
-                html = html.split("").join("
"); - res.write(html); + var html = markdown.toHTML(utils.getFileContents(pathName).toString()); + + html = html.split("").join("
");
+                    html = html.split("").join("
"); + html = html.split("\\`\\`\\`").join("```"); + html = html.split("![](media/").join("![](" + "entries/" + category.url + "/media/"); + res.write(html); + + res.write("
"); + resolve() + }); } catch(ex) { //console.log(ex); //utils.include(res, "includes/404.html"); } - - res.write("
"); - resolve() }); } }; \ No newline at end of file diff --git a/server.js b/server.js index 2a4a5b5..f612259 100644 --- a/server.js +++ b/server.js @@ -7,6 +7,8 @@ const http = require('http'); +var https = require('https'); + const url = require('url'); var express = require("express"); @@ -15,8 +17,23 @@ var session = require('express-session'); const includes = require('./includes/includes.js'); +var forceSsl = require('express-force-ssl'); + var app = express(); +var fs = require('fs'); + +//var key = fs.readFileSync('private.key'); +//var cert = fs.readFileSync( 'primary.crt' ); +//var ca = fs.readFileSync( 'encryption/intermediate.crt' ); + +// var options = { +// key: key, +// cert: cert, +// ca: ca +// }; + +//the secret is different on production app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 6000000 }})); app.use(function(request, res) @@ -25,7 +42,7 @@ app.use(function(request, res) var filename = q.pathname; //handles image requests - if(filename.includes("/img/")) + if(filename.includes("/img/") || filename.includes(".jpg")) { require("./img/image.js").main(res, filename); } @@ -38,7 +55,7 @@ app.use(function(request, res) var file = ""; if(filename === '' || filename === '/') - filename = '/category/Java'; + filename = '/category/projects'; var urlSplit = filename.split("/"); @@ -62,7 +79,10 @@ app.use(function(request, res) //console.log("fin"); //for debugging }) } - }); -http.createServer(app).listen(8080); \ No newline at end of file +//https.createServer(options, app).listen(443); + +http.createServer(app).listen(80); + +//app.use(forceSsl); \ No newline at end of file diff --git a/utils/sql.js b/utils/sql.js index cd8befe..7e1edb0 100644 --- a/utils/sql.js +++ b/utils/sql.js @@ -11,7 +11,7 @@ const qs = require('querystring'); const con = mysql.createConnection({ host: "localhost", user: "blog_user", - password: "password", + password: "password", //definitely not the password on production database: "blog_name" }); @@ -31,7 +31,7 @@ var fetch = function(sqlStatement) { con.query(sqlStatement, function (err, result) { - if (err) + if(err) { reject(); } @@ -130,13 +130,11 @@ module.exports= return new Promise(function(resolve, reject) { var q = "select * from categories where name ='" + requestURL + "' limit 1"; - console.log(q); fetch(q).then(function(categories) { if(categories.length != 0) { var qPosts = "select * from posts where category_id='" + categories[0].category_id + "'"; - console.log(qPosts); resolve(fetch(qPosts)); } else @@ -251,5 +249,10 @@ module.exports= resolve(result); } }); + }, + + getCategory: function(categoryId) + { + return fetch("select * from categories where category_id='" + categoryId + "'"); } }; \ No newline at end of file