From 4963cbe0aaac64ac5885c0f7c0703f38a898d063 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 9 Mar 2019 13:33:35 -0500 Subject: [PATCH] Got the project sites working and fixed bug with pagination bar. --- blog/renderNextBar.js | 8 ++++-- includes/includes.js | 2 +- routes/includes/index.js | 10 ------- routes/index.js | 4 ++- routes/projects/index.js | 24 +++++++++++++++- server.js | 59 ---------------------------------------- sites/projects.js | 1 - 7 files changed, 32 insertions(+), 76 deletions(-) diff --git a/blog/renderNextBar.js b/blog/renderNextBar.js index 4453ae4..6933f7e 100644 --- a/blog/renderNextBar.js +++ b/blog/renderNextBar.js @@ -40,14 +40,16 @@ module.exports= var nextPage = currentPage + 1; var previousPage = currentPage - 1; + + var strippedURL = baseURL.split("?page=")[0]; if (isValidPage(previousPage, postsPerPage, totalPosts)) { - paginationObject.previous = {url: baseURL + "?page=" + previousPage}; + paginationObject.previous = {url: strippedURL + "?page=" + previousPage}; } if (isValidPage(nextPage, postsPerPage, totalPosts)) { - paginationObject.next = {url: baseURL + "?page=" + nextPage}; + paginationObject.next = {url: strippedURL + "?page=" + nextPage}; } var page = 1; @@ -60,7 +62,7 @@ module.exports= } else { - pages.push({number: page, url: baseURL + "?page=" + page}) + pages.push({number: page, url: strippedURL + "?page=" + page}) } page = page + 1; } diff --git a/includes/includes.js b/includes/includes.js index 4e7a32c..910b2d2 100644 --- a/includes/includes.js +++ b/includes/includes.js @@ -201,7 +201,7 @@ module.exports = */ sendHTML: function(result, fileName) { - readFile("." + fileName).then(function(content) + readFile(fileName).then(function(content) { result.writeHead(200, {'Content-Type': 'text/html'}); result.write(content); diff --git a/routes/includes/index.js b/routes/includes/index.js index 31b705d..8503dc6 100644 --- a/routes/includes/index.js +++ b/routes/includes/index.js @@ -1,22 +1,12 @@ const routes = require('express').Router(); -/** used to parse the request URL */ -const url = require('url'); - const contentLoader = require('../../includes/staticContentServer.js'); - - routes.get('*', (request, result) => { - var filename = url.parse(request.url, true).pathname; - console.log(request.originalURL); - console.log(request.url.path); if(!contentLoader.serveStaticContent(request, result, request.originalUrl, "")) { - - //missing content } }); diff --git a/routes/index.js b/routes/index.js index b453916..9256e64 100644 --- a/routes/index.js +++ b/routes/index.js @@ -28,7 +28,9 @@ routes.use('/category', category); const pageBuilder = require('../utils/pageBuilder'); -const projects = ["/steam/"]; +const project = require('./projects'); +routes.use('/steam', project); + //blog home page diff --git a/routes/projects/index.js b/routes/projects/index.js index 5c68232..456e378 100644 --- a/routes/projects/index.js +++ b/routes/projects/index.js @@ -1,8 +1,30 @@ const routes = require('express').Router(); -routes.get('/', (request, result) => +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; \ No newline at end of file diff --git a/server.js b/server.js index 7e8ea56..c28ba88 100644 --- a/server.js +++ b/server.js @@ -17,13 +17,9 @@ const express = require("express"); /** express app */ const app = express(); -/** server side logging */ -const sql = require('./utils/sql'); - /** Used for gzip compression */ const compression = require('compression'); - /**Updates the site map whenever the server is started */ const map = require('./utils/generateSiteMap.js'); map.main(); @@ -35,64 +31,9 @@ const session = require('express-session'); /**Initializes sessions for login */ app.use(session({ secret: config.SESSION_SECRET, cookie: { maxAge: 6000000 }})); - - - const routes = require('./routes'); app.use('/', routes); -// /** -// * Parses the request url and calls correct JS files -// */ -// app.use(function(request, result) -// { -// //prevents people from pointing their dns at my IP:port for my site -// if(request.headers.host.includes("localhost:" + port) || -// request.headers.host.includes("jrtechs.net")) -// { -// const filename = url.parse(request.url, true).pathname; -// -// var project = false; -// projects.forEach(function(projectName) -// { -// if(filename.startsWith(projectName)) -// { -// require("./sites/projects.js").main(request, result, projectName); -// project = true; -// } -// }); -// -// if(filename.startsWith("/admin")) -// { -// require("./sites/admin.js").main(request, result, filename); -// project = true; -// } -// -// if(!project) -// { -// require("./sites/blog.js").main(request, result, filename); -// } -// -// try -// { -// const getClientAddress = (request.headers['x-forwarded-for'] || '').split(',')[0] -// || request.connection.remoteAddress; -// console.log(getClientAddress); -// -// sql.logTraffic(getClientAddress, filename); -// } -// catch (e) -// { } -// } -// else -// { -// // utils.printWrongHost(result); -// result.writeHead(418, {}); -// result.end(); -// } -// }); - - //enables gzip compression for the site app.use(compression()); diff --git a/sites/projects.js b/sites/projects.js index 366ba47..976511a 100644 --- a/sites/projects.js +++ b/sites/projects.js @@ -29,7 +29,6 @@ module.exports= filename = baseURL + "index.html"; } - if (!contentLoader.serveStaticContent(request, result, filename, "/blogContent/projects")) { console.log(filename);