@ -0,0 +1,85 @@ | |||||
/** | |||||
* Main server file for the blog. This file is responsible for | |||||
* creating the server and listening for clients. The main run | |||||
* function parses the url and calls a sub module to make the | |||||
* appropriate pages. | |||||
* | |||||
* @author Jeffery Russell 7-21-18 | |||||
*/ | |||||
const http = require('http'); | |||||
const url = require('url'); | |||||
const express = require("express"); | |||||
const session = require('express-session'); | |||||
const includes = require('./includes/includes.js'); | |||||
const app = express(); | |||||
const utils = require('./utils/utils.js'); | |||||
const port = 8001; | |||||
const cache = require('memory-cache'); | |||||
/** Initializes sessions for login */ | |||||
app.use(session({ secret: utils.getFileLine('../session_secret'), cookie: { maxAge: 6000000 }})); | |||||
/** | |||||
* Parses the request url and calls correct JS files | |||||
*/ | |||||
app.use(function(request, res) | |||||
{ | |||||
if(request.headers.host.includes("localhost:" + port) || | |||||
request.headers.host.includes("jrtechs.net")) | |||||
{ | |||||
const filename = url.parse(request.url, true).pathname; | |||||
//handles image requests | |||||
if(filename.includes("/img/") || filename.includes(".jpg") || filename.includes(".png")) | |||||
{ | |||||
require("./img/image.js").main(res, filename, cache); | |||||
} | |||||
else if(filename.includes("/css/") || filename.includes(".woff2")) | |||||
{ | |||||
includes.sendCSS(res, filename, cache) | |||||
} | |||||
else if(filename.includes("/js/") || filename.includes(".js")) | |||||
{ | |||||
require("./js/js.js").main(res, filename, cache); | |||||
} | |||||
else | |||||
{ | |||||
res.writeHead(200, {'Content-Type': 'text/html'}); | |||||
file = "./admin/admin.js"; | |||||
Promise.all([includes.printAdminHeader(), | |||||
require(file).main(filename, request), | |||||
includes.printFooter()]).then(function(content) | |||||
{ | |||||
res.write(content.join('')); | |||||
res.end(); | |||||
}).catch(function(err) | |||||
{ | |||||
console.log(err); | |||||
throw err; | |||||
}); | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
// utils.printWrongHost(res); | |||||
res.writeHead(418, {}); | |||||
res.end(); | |||||
} | |||||
}); | |||||
http.createServer(app).listen(port); | |||||
@ -0,0 +1,62 @@ | |||||
<!DOCTYPE html> | |||||
<html lang="en"> | |||||
<head> | |||||
<title>Jrtechs</title> | |||||
<meta charset="UTF-8"> | |||||
<meta name="viewport" content="width=device-width, initial-scale=1"> | |||||
<link rel="stylesheet" href="/css/code.css" media="screen"> | |||||
<link rel="stylesheet" href="/css/bootstrap.css" media="screen"> | |||||
<meta name="description" content="Blog of Jeffery Russell, featuring technical guides, and projects."> | |||||
<meta name="author" content="Jeffery Russell"> | |||||
<style> | |||||
html, body, h1, h2, h3, h4, h5, h6 { | |||||
font-family: 'Open Sans', sans-serif; | |||||
} | |||||
p{font-size:18px;} | |||||
</style> | |||||
</head> | |||||
<body> | |||||
<div class="navbar navbar-expand-lg navbar-dark fixed-top bg-primary" id="mainNav"> | |||||
<div class="container"> | |||||
<a class="navbar-brand" href="#">Jrtechs</a> | |||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" | |||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | |||||
<span class="navbar-toggler-icon"></span> | |||||
</button> | |||||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | |||||
<ul class="navbar-nav mr-auto"> | |||||
<li class="nav-item active"> | |||||
<a class="nav-link" href="https://jrtechs.net">Home <span class="sr-only">(current)</span></a> | |||||
</li> | |||||
<li class="nav-item"> | |||||
<a class="nav-link" href="https://jrtechs.me/#contact">Contact</a> | |||||
</li> | |||||
</ul> | |||||
<ul class="nav navbar-nav navbar-right"> | |||||
<li class="nav-item"> | |||||
<a class="nav-link" href="https://jrtechs.me">Resume</a> | |||||
</li> | |||||
<li class="nav-item"> | |||||
<a class="nav-link" href="https://github.com/jrtechs">Github</a> | |||||
</li> | |||||
<li class="nav-item"> | |||||
<a class="nav-link" href="https://www.youtube.com/c/JrtechsNet">Youtube</a> | |||||
</li> | |||||
</ul> | |||||
</div> | |||||
</div> | |||||
</div> | |||||
<br><br><br><br><br> | |||||
<div class="container"> | |||||
<div class="row"> |