Browse Source

Modified this code to work with "other projects" and render SVG images properly.

pull/26/head
jrtechs 6 years ago
parent
commit
dd2fe9f067
2 changed files with 23 additions and 10 deletions
  1. +8
    -7
      includes/projects.js
  2. +15
    -3
      server.js

+ 8
- 7
includes/projects.js View File

@ -1,9 +1,6 @@
//file io //file io
const utils = require('../utils/utils.js'); const utils = require('../utils/utils.js');
//DB queries
const sql = require('../utils/sql');
//used to parse the request URL //used to parse the request URL
const url = require('url'); const url = require('url');
@ -21,13 +18,17 @@ module.exports=
* @param requestURL * @param requestURL
* @returns {Promise|*} * @returns {Promise|*}
*/ */
main: function(request, result)
main: function(request, result, baseURL)
{ {
//const filename = url.parse(request.url, true).pathname //const filename = url.parse(request.url, true).pathname
var filename = url.parse(request.url, true).pathname; var filename = url.parse(request.url, true).pathname;
if(filename.includes("/img/") || filename.includes(".jpg") ||
if(filename.includes(".svg") || filename.includes(".svg"))
{
result.writeHead(200, {'Content-Type': 'image/svg+xml'});
}
else if(filename.includes("/img/") || filename.includes(".jpg") ||
filename.includes(".png") || filename.includes(".ico")) filename.includes(".png") || filename.includes(".ico"))
{ {
result.writeHead(200, {'Content-Type': 'image/png'}); result.writeHead(200, {'Content-Type': 'image/png'});
@ -46,9 +47,9 @@ module.exports=
result.writeHead(200, {'Content-Type': 'text/html'}); result.writeHead(200, {'Content-Type': 'text/html'});
} }
if(filename == "/steam" || filename == "/steam/")
if(filename == baseURL || filename == baseURL.substring(0, baseURL.length - 1))
{ {
filename = "/steam/index.html";
filename = baseURL + "index.html";
} }
utils.include("./blogContent/projects" + filename).then(function(content) utils.include("./blogContent/projects" + filename).then(function(content)

+ 15
- 3
server.js View File

@ -37,6 +37,7 @@ map.main();
//port for the server to run on //port for the server to run on
const port = 8000; const port = 8000;
const projects = ["/steam/"];
/** /**
* Parses the request url and calls correct JS files * Parses the request url and calls correct JS files
@ -49,15 +50,26 @@ app.use(function(request, result)
{ {
const filename = url.parse(request.url, true).pathname; const filename = url.parse(request.url, true).pathname;
var project = false;
projects.forEach(function(projectName)
{
if(filename.includes(projectName))
{
require("./includes/projects.js").main(request, result, projectName);
project = true;
}
});
if (filename.includes("/steam/"))
if(project)
{ {
require("./includes/projects.js").main(request, result);
//don't do blog stuff
} }
//handles image requests //handles image requests
else if(filename.includes("/img/") || filename.includes(".jpg") || else if(filename.includes("/img/") || filename.includes(".jpg") ||
filename.includes(".png") || filename.includes(".ico"))
filename.includes(".png") || filename.includes(".ico")
|| filename.includes(".svg"))
{ {
includes.sendImage(result, filename, cache); includes.sendImage(result, filename, cache);
} }

Loading…
Cancel
Save