diff --git a/includes/html/footer.html b/includes/html/footer.html
index 22c86fe..b97435b 100644
--- a/includes/html/footer.html
+++ b/includes/html/footer.html
@@ -59,7 +59,9 @@
diff --git a/includes/html/header.html b/includes/html/header.html
index a3d27d5..0602309 100644
--- a/includes/html/header.html
+++ b/includes/html/header.html
@@ -65,6 +65,9 @@
Contact
+
+ Posts
+
Photography
diff --git a/routes/about.js b/routes/about.js
deleted file mode 100644
index c0832d3..0000000
--- a/routes/about.js
+++ /dev/null
@@ -1,17 +0,0 @@
-const routes = require('express').Router();
-
-const pageBuilder = require('../utils/pageBuilder');
-
-routes.get('/', (request, result) =>
-{
- pageBuilder.buildPageWithTemplate(request, result,
- (p1,p2,p3)=>{}, "blog/about.html");
-});
-
-
-routes.get('*', (request, result) =>
-{
- pageBuilder.print404(result);
-});
-
-module.exports = routes;
\ No newline at end of file
diff --git a/routes/api/index.js b/routes/api/index.js
new file mode 100644
index 0000000..559368b
--- /dev/null
+++ b/routes/api/index.js
@@ -0,0 +1,38 @@
+const routes = require('express').Router();
+const sql = require('../../utils/sql');
+
+const renderPost = require('../../blog/renderBlogPost');
+
+routes.get('/posts', (request, result) =>
+{
+ sql.getAllPosts().then((data)=>
+ {
+ result.json(data).end();
+ }).catch((err)=>
+ {
+ result.status(500).json([]).end();
+ });
+});
+
+
+routes.get('/render/:postID', (request, result) =>
+{
+ sql.getPostById(request.params.postID).then((sqlData)=>
+ {
+ renderPost.generateBlogPost(sqlData, -1).then((rendered)=>
+ {
+ result.json(rendered).end();
+ });
+ }).catch((err)=>
+ {
+ result.status(404).json({error: 404}).end();
+ })
+
+});
+
+routes.get('*', (request, result) =>
+{
+ result.json([]).end();
+});
+
+module.exports = routes;
\ No newline at end of file
diff --git a/routes/index.js b/routes/index.js
index 517d077..bc9b491 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -1,8 +1,8 @@
const routes = require('express').Router();
-/** about page */
-const about = require('./about');
-routes.use('/about', about);
+// /** about page */
+// const about = require('./about');
+// routes.use('/about', about);
/** admin page and all of its sub pages */
const admin = require('./admin');
@@ -33,10 +33,25 @@ routes.use('/category', category);
const pageBuilder = require('../utils/pageBuilder');
+routes.get('/about', (request, result) =>
+{
+ pageBuilder.buildPageWithTemplate(request, result,
+ (p1,p2,p3)=>{}, "blog/about.html");
+});
+
+
+routes.get('/posts', (request, result) =>
+{
+ pageBuilder.buildPageWithTemplate(request, result,
+ (p1,p2,p3)=>{}, "blog/posts.html");
+});
+
+
const project = require('./projects');
routes.use('/steam', project);
-
+const api = require('./api');
+routes.use('/api', api);
//blog home page
routes.get('/', (request, result) =>
diff --git a/templates/blog/posts.html b/templates/blog/posts.html
new file mode 100644
index 0000000..565847b
--- /dev/null
+++ b/templates/blog/posts.html
@@ -0,0 +1,257 @@
+{header}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{footer}
\ No newline at end of file
diff --git a/utils/sql.js b/utils/sql.js
index f443da7..ad85a1a 100644
--- a/utils/sql.js
+++ b/utils/sql.js
@@ -22,6 +22,7 @@ const config = require('../utils/configLoader').getConfig();
/** SQL connection */
const con = mysql.createConnection({
host: config.SQL_HOST,
+ port: config.SQL_PORT,
user: config.SQL_USER,
password: config.SQL_PASSWORD,
database: config.SQL_DATABASE
@@ -156,15 +157,20 @@ module.exports=
*/
getPostById: function(id)
{
- console.log("select * from posts where post_id='" + id + "' limit 1");
-
- return new Promise(function(resolve, reject)
+ return new Promise((resolve, reject)=>
{
fetch("select * from posts where post_id='" + id + "' limit 1")
.then(function(post)
{
- resolve(post[0]);
- }).catch(function(error)
+ if(post.length === 1)
+ {
+ resolve(post[0]);
+ }
+ else
+ {
+ reject();
+ }
+ }).catch((error)=>
{
reject(error);
});