diff --git a/README.md b/README.md index 88e168b..f69f85a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # NodeJSBlog Recreating my wordpress blog in node JS. -##MYSQL Information +## MYSQL Information -'''sql +```SQL create database blog_name; use blog_name; @@ -44,4 +44,9 @@ primary key(popular_post_id) grant all on blog_name.* to blog_user@localhost identified by "password"; -''' +``` + +## Node Dependencies +```bash +npm install mysql +``` diff --git a/admin/admin.js b/admin/admin.js new file mode 100644 index 0000000..1878207 --- /dev/null +++ b/admin/admin.js @@ -0,0 +1,7 @@ +module.exports= +{ + main: function(res, fileName) + { + + } +}; \ No newline at end of file diff --git a/admin/test.html b/admin/test.html new file mode 100644 index 0000000..a0559c6 --- /dev/null +++ b/admin/test.html @@ -0,0 +1,295 @@ + + + + + +W3.CSS Template + + + + + + + + + + + + + + + + + +
+ + + + + +
+ +

MY BLOG

+ +

Welcome to the blog of unknown

+ +
+ + + + + +
+ + + + + +
+ + + +
+ + Nature + +
+ +

TITLE HEADING

+ +
Title description, April 7, 2014
+ +
+ + + +
+ +

Mauris neque quam, fermentum ut nisl vitae, convallis maximus nisl. Sed mattis nunc id lorem euismod placerat. Vivamus porttitor magna enim, ac accumsan tortor cursus at. Phasellus sed ultricies mi non congue ullam corper. Praesent tincidunt sed + + tellus ut rutrum. Sed vitae justo condimentum, porta lectus vitae, ultricies congue gravida diam non fringilla.

+ +
+ +
+ +

+ +
+ +
+ +

Comments   0

+ +
+ +
+ +
+ +
+ +
+ + + + + +
+ + Norway + +
+ +

BLOG ENTRY

+ +
Title description, April 2, 2014
+ +
+ + + +
+ +

Mauris neque quam, fermentum ut nisl vitae, convallis maximus nisl. Sed mattis nunc id lorem euismod placerat. Vivamus porttitor magna enim, ac accumsan tortor cursus at. Phasellus sed ultricies mi non congue ullam corper. Praesent tincidunt sed + + tellus ut rutrum. Sed vitae justo condimentum, porta lectus vitae, ultricies congue gravida diam non fringilla.

+ +
+ +
+ +

+ +
+ +
+ +

Comments   2

+ +
+ +
+ +
+ +
+ + + +
+ + + + +
+ + + +
+ + + +
+ +

My Name

+ +

Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.

+ +
+ +

+ + + + + +
+ +
+ +

Popular Posts

+ +
+ +
    + +
  • + + Image + + Lorem
    + + Sed mattis nunc + +
  • + +
  • + + Image + + Ipsum
    + + Praes tinci sed + +
  • + +
  • + + Image + + Dorum
    + + Ultricies congue + +
  • + +
  • + + Image + + Mingsum
    + + Lorem ipsum dipsum + +
  • + +
+ +
+ +
+ + + + + +
+ +
+ +

Tags

+ +
+ +
+ +

Travel New York London + + IKEA NORWAY DIY + + Ideas Baby Family + + News Clothing Shopping + + Sports Games + +

+ +
+ +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/includes/footer.html b/includes/footer.html index 02f25f5..06c4f9c 100644 --- a/includes/footer.html +++ b/includes/footer.html @@ -1,5 +1,5 @@ - + diff --git a/includes/header.html b/includes/header.html index d0dd411..58dc623 100644 --- a/includes/header.html +++ b/includes/header.html @@ -29,4 +29,5 @@ -
\ No newline at end of file +
+
\ No newline at end of file diff --git a/includes/sidebar.html b/includes/sidebar.html new file mode 100644 index 0000000..6043ced --- /dev/null +++ b/includes/sidebar.html @@ -0,0 +1,114 @@ + +
+ + + +
+ + + +
+ +

My Name

+ +

Just me, myself and I, exploring the universe of uknownment. I have a heart of love and a interest of lorem ipsum and mauris neque quam blog. I want to share my world with you.

+ +
+ +

+ + + + + +
+ +
+ +

Popular Posts

+ +
+ +
    + +
  • + + Image + + Lorem
    + + Sed mattis nunc + +
  • + +
  • + + Image + + Ipsum
    + + Praes tinci sed + +
  • + +
  • + + Image + + Dorum
    + + Ultricies congue + +
  • + +
  • + + Image + + Mingsum
    + + Lorem ipsum dipsum + +
  • + +
+ +
+ +
+ + + + + +
+ +
+ +

Tags

+ +
+ +
+ +

Travel New York London + + IKEA NORWAY DIY + + Ideas Baby Family + + News Clothing Shopping + + Sports Games + +

+ +
+ +
+ + + + + +
\ No newline at end of file diff --git a/includes/sidebar.js b/includes/sidebar.js new file mode 100644 index 0000000..99ded45 --- /dev/null +++ b/includes/sidebar.js @@ -0,0 +1,9 @@ +const utils = require('../utils/utils.js'); + +module.exports= +{ + main: function(res, fileName) + { + utils.include(res,"includes/sidebar.html"); + } +}; \ No newline at end of file diff --git a/posts/category.js b/posts/category.js index e69de29..98876bb 100644 --- a/posts/category.js +++ b/posts/category.js @@ -0,0 +1,11 @@ + + + + +module.exports= +{ + main: function(res, fileName) + { + + } +}; \ No newline at end of file diff --git a/posts/posts.js b/posts/posts.js new file mode 100644 index 0000000..d05240a --- /dev/null +++ b/posts/posts.js @@ -0,0 +1,17 @@ +const utils = require('../utils/utils.js'); + + +module.exports= +{ + /** + * Function which parses a url and displays appropriate post + * + * @param res + * @param fileName request url + */ + main: function(res, requestURL) + { + + require("../includes/sidebar.js").main(res, requestURL); + } +}; \ No newline at end of file diff --git a/posts/singlePost.js b/posts/singlePost.js new file mode 100644 index 0000000..1878207 --- /dev/null +++ b/posts/singlePost.js @@ -0,0 +1,7 @@ +module.exports= +{ + main: function(res, fileName) + { + + } +}; \ No newline at end of file diff --git a/server.js b/server.js index 910a8e6..53bf1f6 100644 --- a/server.js +++ b/server.js @@ -10,10 +10,10 @@ const http = require('http'); const url = require('url'); const includes = require('./includes/includes.js'); -http.createServer(function (req, res) +http.createServer(function (request_url, res) { - var q = url.parse(req.url, true); - var filename = "." + q.pathname; + var q = url.parse(request_url.url, true); + var filename = q.pathname; //prints header includes.printHeader(res); @@ -21,6 +21,7 @@ http.createServer(function (req, res) if(filename.includes("/category")) { //categories or view a category page + } else if(filename.includes("/downloads/")) { @@ -30,10 +31,12 @@ http.createServer(function (req, res) else if(filename.includes("/admin")) { //admin page + } else { //normal blog entry + require("./posts/posts.js").main(res, filename); } //includes footer file diff --git a/utils/sql.js b/utils/sql.js new file mode 100644 index 0000000..eebe7ee --- /dev/null +++ b/utils/sql.js @@ -0,0 +1,54 @@ +const mysql = require('mysql'); + +const con = mysql.createConnection({ + host: "localhost", + user: "yourusername", + password: "yourpassword" +}); + +con.connect(function(err) { + if (err) throw err; + console.log("Connected!"); +}); + +module.exports= +{ + /** + * Function used to query the database for records + * + * @param sqlStatement + * @returns {Array} + */ + fetch : function(sqlStatement) + { + con.connect(function(err) + { + if (err) throw err; + con.query(sqlStatement, function (err, result) + { + if (err) throw err; + return result; + }); + }); + return []; + }, + /** + * Function used to use insert statements into the database + * + * @param sqlStatement + * @return the id of the new record - if there is one + */ + insert : function(sqlStatement) + { + con.connect(function(err) + { + if (err) throw err; + con.query(sqlStatement, function (err, result) + { + if (err) throw err; + return result.insertId; + }); + }); + return 0; + } +}; \ No newline at end of file