@ -0,0 +1,16 @@ | |||||
const routes = require('express').Router(); | |||||
const utils = require('../utils/utils.js'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
}); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
utils.print404(result); | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,10 @@ | |||||
const routes = require('express').Router(); | |||||
const builder = require('../../utils/pageBuilder'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/analytics").main) | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,18 @@ | |||||
const routes = require('express').Router(); | |||||
const builder = require('../../utils/pageBuilder'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/adminDownloads").main) | |||||
}); | |||||
routes.post('/', (request, result) => | |||||
{ | |||||
builder.adminPostRoute(request ,require("../../admin/adminDownloads").processPostData).then(function() | |||||
{ | |||||
result.redirect('/admin/downloads'); | |||||
}) | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,38 @@ | |||||
const routes = require('express').Router(); | |||||
const analytics = require('./analytics'); | |||||
routes.use('/analytics', analytics); | |||||
const login = require('./login'); | |||||
routes.use('/login', login); | |||||
const posts = require('./posts'); | |||||
routes.use('/posts', posts); | |||||
const downloads = require('./downloads'); | |||||
routes.use('/downloads', downloads); | |||||
const users = require('./users'); | |||||
routes.use('/users', users); | |||||
const builder = require('../../utils/pageBuilder.js'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/adminHome").main) | |||||
}); | |||||
routes.post('/', (request, result) => | |||||
{ | |||||
builder.adminPostRoute(request, require("../../admin/adminHome").processPostData).then(function() | |||||
{ | |||||
result.redirect("/admin"); | |||||
}); | |||||
}); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
builder.print404(result); | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,16 @@ | |||||
const routes = require('express').Router(); | |||||
const builder = require('../../utils/pageBuilder.js'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/adminHome").main) | |||||
}); | |||||
routes.post('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/login").main) | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,15 @@ | |||||
const routes = require('express').Router(); | |||||
const builder = require('../../utils/pageBuilder'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/posts").main) | |||||
}); | |||||
routes.post('/', (request, result) => | |||||
{ | |||||
builder.adminPostPageWithOutput(request, result ,require("../../admin/posts").processPostData) | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,15 @@ | |||||
const routes = require('express').Router(); | |||||
const builder = require('../../utils/pageBuilder.js'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
builder.constructAdminPage(request, result, require("../../admin/users").main) | |||||
}); | |||||
routes.post('/', (request, result) => | |||||
{ | |||||
builder.adminPostPageWithOutput(request, result ,require("../../admin/users").processPostData) | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,10 @@ | |||||
const routes = require('express').Router(); | |||||
const pageBuilder = require('../../utils/pageBuilder'); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
pageBuilder.buildBlogPage(request, result, require("../../blog/category").main) | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,15 @@ | |||||
const routes = require('express').Router(); | |||||
const utils = require('../utils/utils.js'); | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
require("../blog/contact.js").main(request, result); | |||||
}); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
utils.print404(result); | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,14 @@ | |||||
const routes = require('express').Router(); | |||||
/** used to parse the request URL */ | |||||
const url = require('url'); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
console.log("ping"); | |||||
const filename = url.parse(request.url, true).pathname; | |||||
require("../../includes/downloads.js").main(result, filename); | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,15 @@ | |||||
const routes = require('express').Router(); | |||||
const contentLoader = require('../../includes/staticContentServer.js'); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
if(!contentLoader.serveStaticContent(request, result, request.originalUrl, "")) | |||||
{ | |||||
//missing content | |||||
} | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,49 @@ | |||||
const routes = require('express').Router(); | |||||
/** about page */ | |||||
const about = require('./about'); | |||||
routes.use('/about', about); | |||||
/** admin page and all of its sub pages */ | |||||
const admin = require('./admin'); | |||||
routes.use('/admin', admin); | |||||
/** Contact page */ | |||||
const contact = require('./contact'); | |||||
routes.use('/contact', contact); | |||||
/** Downloads path for files */ | |||||
const downloads = require('./downloads'); | |||||
routes.use('/downloads', downloads); | |||||
/** static content like css, js, and images */ | |||||
const includes = require('./includes'); | |||||
routes.use('/includes', includes); | |||||
routes.use('/blogContent', includes); | |||||
/** category pages */ | |||||
const category = require('./category'); | |||||
routes.use('/category', category); | |||||
const pageBuilder = require('../utils/pageBuilder'); | |||||
const project = require('./projects'); | |||||
routes.use('/steam', project); | |||||
//blog home page | |||||
routes.get('/', (request, result) => | |||||
{ | |||||
pageBuilder.buildBlogPage(request, result, require("../blog/homePage").main) | |||||
}); | |||||
//regular blog posts | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
pageBuilder.buildBlogPage(request, result, | |||||
require("../blog/posts").main, request.url); | |||||
}); | |||||
module.exports = routes; |
@ -0,0 +1,30 @@ | |||||
const routes = require('express').Router(); | |||||
const url = require('url'); | |||||
const contentLoader = require('../../includes/staticContentServer.js'); | |||||
routes.get('*', (request, result) => | |||||
{ | |||||
var filename = url.parse(request.url, true).pathname; | |||||
var extra = ''; | |||||
if(filename === '/') | |||||
{ | |||||
if(request.originalUrl.charAt(request.originalUrl.length -1) !== '/') | |||||
{ | |||||
result.redirect(request.originalUrl + "/"); | |||||
} | |||||
else | |||||
{ | |||||
extra = "/index.html"; | |||||
} | |||||
} | |||||
if(!contentLoader.serveStaticContent(request, result, | |||||
request.originalUrl + extra, "blogContent/projects")) | |||||
{ | |||||
} | |||||
}); | |||||
module.exports = routes; |
@ -1,55 +0,0 @@ | |||||
//sending static content | |||||
const includes = require('../includes/includes.js'); | |||||
//used to append static content to result | |||||
const contentLoader = require('../includes/staticContentServer.js'); | |||||
const whiskers = require('whiskers'); | |||||
/** | |||||
* @author Jeffery Russell 11-3-18 | |||||
* | |||||
* @type {{main: (function(*=, *): Promise)}} | |||||
*/ | |||||
module.exports= | |||||
{ | |||||
/** | |||||
* Calls blog and sidebar modules to render blog contents in order | |||||
* | |||||
* @param requestURL | |||||
* @returns {Promise|*} | |||||
*/ | |||||
main: function(request, result, filename) | |||||
{ | |||||
if(contentLoader.serveStaticContent(request, result, filename, "")) | |||||
{ | |||||
//do nothing | |||||
} | |||||
else | |||||
{ | |||||
const clientAddress = (request.headers['x-forwarded-for'] || '').split(',')[0] | |||||
|| request.connection.remoteAddress; | |||||
result.writeHead(200, {'Content-Type': 'text/html'}); | |||||
const file = "../admin/admin.js"; | |||||
var templateContext = Object(); | |||||
Promise.all([includes.fetchTemplate("admin/adminMain.html"), | |||||
includes.printAdminHeader(templateContext), | |||||
require(file).main(request, clientAddress, templateContext, filename), | |||||
includes.printFooter(templateContext), | |||||
]).then(function(content) | |||||
{ | |||||
result.write(whiskers.render(content[0], templateContext)); | |||||
result.end(); | |||||
}).catch(function(err) | |||||
{ | |||||
console.log(err); | |||||
throw err; | |||||
}); | |||||
} | |||||
} | |||||
}; |
@ -1,122 +0,0 @@ | |||||
//used to append static content to result | |||||
const includes = require('../includes/includes.js'); | |||||
//used to append static content to result | |||||
const contentLoader = require('../includes/staticContentServer.js'); | |||||
const whiskers = require('whiskers'); | |||||
const TEMPLATE_FILE="blog/blogMain.html"; | |||||
const PAGINATION_TEMPLATE_KEY = "paginationTemplate"; | |||||
const PAGINATION_TEMPLATE_FILE = "blog/paginationBar.html"; | |||||
//caching program to make the application run faster | |||||
const cache = require('memory-cache'); | |||||
//file io | |||||
const utils = require('../utils/utils.js'); | |||||
/** | |||||
* @author Jeffery Russell 11-3-18 | |||||
* | |||||
* @type {{main: (function(*=, *): Promise)}} | |||||
*/ | |||||
module.exports= | |||||
{ | |||||
/** | |||||
* Calls posts and sidebar modules to render blog contents in order | |||||
* | |||||
* @param requestURL | |||||
* @returns {Promise|*} | |||||
*/ | |||||
main: function(request, result, filename) | |||||
{ | |||||
if(contentLoader.serveStaticContent(request, result, filename, "")) | |||||
{ | |||||
//do nothing | |||||
} | |||||
//downloads | |||||
else if (filename.includes("/downloads/")) | |||||
{ | |||||
require("../includes/downloads.js").main(result, filename); | |||||
} | |||||
else if (filename.includes("/contact")) | |||||
{ | |||||
require("../blog/contact.js").main(request, result); | |||||
} | |||||
else | |||||
{ | |||||
var page = request.query.page; | |||||
if(typeof page == "undefined") | |||||
page = 1; | |||||
page = Number(page); | |||||
const html = cache.get(filename + "?page=" + page); | |||||
result.writeHead(200, {'Content-Type': 'text/html'}); | |||||
if (html == null) | |||||
{ | |||||
var file = ""; | |||||
if (filename === '' || filename === '/') | |||||
{ | |||||
file = "../blog/homePage.js"; | |||||
} | |||||
else | |||||
{ | |||||
var urlSplit = filename.split("/"); | |||||
if (urlSplit.length >= 2 && urlSplit[1] === 'category') //single category page | |||||
file = "../blog/category.js"; | |||||
else | |||||
{ | |||||
file = "../blog/posts.js"; | |||||
page = 1; // all blog are single page, everyone must be one to ensure | |||||
// cache is not tricked into storing same blog post a ton of times | |||||
} | |||||
} | |||||
var templateContext = Object(); | |||||
Promise.all([includes.fetchTemplate(TEMPLATE_FILE), | |||||
utils.includeInObject(PAGINATION_TEMPLATE_KEY, templateContext, "templates/" + PAGINATION_TEMPLATE_FILE), | |||||
includes.printHeader(templateContext), | |||||
includes.printFooter(templateContext), | |||||
require(file).main(filename, request, templateContext), | |||||
require("../blog/sidebar.js").main(templateContext)]) | |||||
.then(function (content) | |||||
{ | |||||
const html = whiskers.render(content[0], templateContext); | |||||
result.write(html); | |||||
result.end(); | |||||
cache.put(filename + "?page=" + page, html); | |||||
}).catch(function (err) | |||||
{ | |||||
console.log(err); | |||||
cache.del(filename + "?page=" + page); | |||||
utils.print404().then(function(content) | |||||
{ | |||||
result.write(content); | |||||
result.end(); | |||||
}) | |||||
}); | |||||
} | |||||
else | |||||
{ | |||||
result.write(html); | |||||
result.end(); | |||||
} | |||||
} | |||||
}, | |||||
/** | |||||
* Clears the memory cache. | |||||
*/ | |||||
clearCache: function() | |||||
{ | |||||
console.log("Blog cache cleared"); | |||||
cache.clear(); | |||||
} | |||||
}; |
@ -0,0 +1,184 @@ | |||||
const utils = require('./utils'); | |||||
const whiskers = require('whiskers'); | |||||
const includes = require("../includes/includes"); | |||||
const cache = require('memory-cache'); | |||||
/** used to parse the request URL */ | |||||
const url = require('url'); | |||||
const TEMPLATE_FILE="blog/blogMain.html"; | |||||
const PAGINATION_TEMPLATE_KEY = "paginationTemplate"; | |||||
const PAGINATION_TEMPLATE_FILE = "blog/paginationBar.html"; | |||||
module.exports = | |||||
{ | |||||
/** | |||||
* Displays 404 error to user | |||||
* | |||||
* @param result | |||||
* @returns {*} | |||||
*/ | |||||
print404: function(result) | |||||
{ | |||||
includes.include("includes/html/404.html").then(function(html) | |||||
{ | |||||
result.write(html); | |||||
result.end(); | |||||
}) | |||||
}, | |||||
constructAdminPage: function(request, result, templateFiller) | |||||
{ | |||||
var templateContext = Object(); | |||||
var promises = []; | |||||
promises.push(includes.fetchTemplate("admin/adminMain.html")); | |||||
promises.push(includes.printAdminHeader(templateContext)); | |||||
promises.push(includes.printFooter(templateContext)); | |||||
if(module.exports.loggedIn(request)) | |||||
{ | |||||
templateContext.loggedIn = true; | |||||
promises.push(templateFiller(templateContext)); | |||||
} | |||||
else | |||||
{ | |||||
//login | |||||
const clientAddress = (request.headers['x-forwarded-for'] || '').split(',')[0] | |||||
|| request.connection.remoteAddress; | |||||
promises.push(require("../admin/login").main(request, clientAddress,templateContext)); | |||||
} | |||||
Promise.all(promises).then(function(content) | |||||
{ | |||||
result.write(whiskers.render(content[0], templateContext)); | |||||
result.end(); | |||||
}).catch(function(err) | |||||
{ | |||||
console.log(err); | |||||
throw err; | |||||
}); | |||||
}, | |||||
adminPostPageWithOutput: function(request, result, templateFiller) | |||||
{ | |||||
utils.getPostData(request).then(function(postData) | |||||
{ | |||||
var templateContext = Object(); | |||||
var promises = []; | |||||
promises.push(includes.fetchTemplate("admin/adminMain.html")); | |||||
promises.push(includes.printAdminHeader(templateContext)); | |||||
promises.push(includes.printFooter(templateContext)); | |||||
if (module.exports.loggedIn(request)) | |||||
{ | |||||
templateContext.loggedIn = true; | |||||
promises.push(templateFiller(templateContext, postData)); | |||||
} | |||||
else | |||||
{ | |||||
//login | |||||
const clientAddress = (request.headers['x-forwarded-for'] || '').split(',')[0] | |||||
|| request.connection.remoteAddress; | |||||
promises.push(require("../admin/login").main(request, clientAddress, templateContext)); | |||||
} | |||||
Promise.all(promises).then(function (content) | |||||
{ | |||||
result.write(whiskers.render(content[0], templateContext)); | |||||
result.end(); | |||||
}).catch(function (err) { | |||||
console.log(err); | |||||
throw err; | |||||
}); | |||||
}); | |||||
}, | |||||
adminPostRoute: function(request, templateFiller) | |||||
{ | |||||
return new Promise(function(resolve, reject) | |||||
{ | |||||
utils.getPostData(request).then(function(postData) | |||||
{ | |||||
templateFiller(postData).then(function() | |||||
{ | |||||
resolve(); | |||||
}) | |||||
}).catch(function(e) | |||||
{ | |||||
reject(e); | |||||
}) | |||||
}) | |||||
}, | |||||
loggedIn(request) | |||||
{ | |||||
return(request.session && request.session.user); | |||||
}, | |||||
buildBlogPageWithURL: function(request, result, templateFiller, filename) | |||||
{ | |||||
var page = request.query.page; | |||||
if(typeof page == "undefined") | |||||
page = 1; | |||||
page = Number(page); | |||||
const html = cache.get(filename + "?page=" + page); | |||||
result.writeHead(200, {'Content-Type': 'text/html'}); | |||||
if (html == null) | |||||
{ | |||||
var templateContext = Object(); | |||||
Promise.all([includes.fetchTemplate(TEMPLATE_FILE), | |||||
includes.includeInObject(PAGINATION_TEMPLATE_KEY, templateContext, "templates/" + PAGINATION_TEMPLATE_FILE), | |||||
includes.printHeader(templateContext), | |||||
includes.printFooter(templateContext), | |||||
templateFiller(filename, request, templateContext), | |||||
require("../blog/sidebar.js").main(templateContext)]) | |||||
.then(function (content) | |||||
{ | |||||
const html = whiskers.render(content[0], templateContext); | |||||
result.write(html); | |||||
result.end(); | |||||
cache.put(filename + "?page=" + page, html); | |||||
}).catch(function (err) | |||||
{ | |||||
cache.del(filename + "?page=" + page); | |||||
module.exports.print404(result) | |||||
}); | |||||
} | |||||
else | |||||
{ | |||||
result.write(html); | |||||
result.end(); | |||||
} | |||||
}, | |||||
buildBlogPage: function(request, result, templateFiller) | |||||
{ | |||||
var filename = url.parse(request.url, true).pathname; | |||||
module.exports.buildBlogPageWithURL(request, result,templateFiller, filename); | |||||
}, | |||||
/** | |||||
* Clears the memory cache. | |||||
*/ | |||||
clearCache: function() | |||||
{ | |||||
console.log("Blog cache cleared"); | |||||
cache.clear(); | |||||
} | |||||
}; |