From a937a97f412b6dbd109c5cbae4634f160b9e0c31 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sat, 2 Mar 2019 17:07:05 -0500 Subject: [PATCH] Created files for the routes used in this project. --- package.json | 1 + routes/about.js | 14 +++++ routes/admin/analytics.js | 8 +++ routes/admin/downloads.js | 8 +++ routes/admin/index.js | 35 ++++++++++++ routes/admin/login.js | 8 +++ routes/admin/posts.js | 8 +++ routes/admin/users.js | 8 +++ routes/category/index.js | 8 +++ routes/contact.js | 13 +++++ routes/downloads/index.js | 9 +++ routes/includes/index.js | 9 +++ routes/index.js | 24 ++++++++ routes/projects/index.js | 8 +++ server.js | 115 +++++++++++++++++++------------------- 15 files changed, 218 insertions(+), 58 deletions(-) create mode 100644 routes/about.js create mode 100644 routes/admin/analytics.js create mode 100644 routes/admin/downloads.js create mode 100644 routes/admin/index.js create mode 100644 routes/admin/login.js create mode 100644 routes/admin/posts.js create mode 100644 routes/admin/users.js create mode 100644 routes/category/index.js create mode 100644 routes/contact.js create mode 100644 routes/downloads/index.js create mode 100644 routes/includes/index.js create mode 100644 routes/index.js create mode 100644 routes/projects/index.js diff --git a/package.json b/package.json index 802a1d6..32f89e7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "promise": "^8.0.1", "remarkable": "^1.7.1", "request": "^2.88.0", + "routes": "^2.1.0", "sanitizer": "^0.1.3", "sendmail": "^1.4.1" }, diff --git a/routes/about.js b/routes/about.js new file mode 100644 index 0000000..9d95db2 --- /dev/null +++ b/routes/about.js @@ -0,0 +1,14 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + + +routes.get('*', (request, result) => +{ + //error +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/admin/analytics.js b/routes/admin/analytics.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/admin/analytics.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/admin/downloads.js b/routes/admin/downloads.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/admin/downloads.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/admin/index.js b/routes/admin/index.js new file mode 100644 index 0000000..cdb51cc --- /dev/null +++ b/routes/admin/index.js @@ -0,0 +1,35 @@ +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); + +routes.get('/', (request, result) => +{ + if(utils.checkPrivilege(request) >= utils.PRIVILEGE.MEMBER) + { + utils.renderHTML(request, result, "users.html", getUserInformation); + } + else + { + utils.printError(result, "You need to be logged in"); + } +}); + +routes.get('*', (request, result) => +{ + //error +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/admin/login.js b/routes/admin/login.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/admin/login.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/admin/posts.js b/routes/admin/posts.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/admin/posts.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/admin/users.js b/routes/admin/users.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/admin/users.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/category/index.js b/routes/category/index.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/category/index.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/contact.js b/routes/contact.js new file mode 100644 index 0000000..b6d1ffc --- /dev/null +++ b/routes/contact.js @@ -0,0 +1,13 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +routes.get('*', (request, result) => +{ + //error +}); + +module.exports = routes; \ No newline at end of file diff --git a/routes/downloads/index.js b/routes/downloads/index.js new file mode 100644 index 0000000..887044f --- /dev/null +++ b/routes/downloads/index.js @@ -0,0 +1,9 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + + +module.exports = routes; \ No newline at end of file diff --git a/routes/includes/index.js b/routes/includes/index.js new file mode 100644 index 0000000..887044f --- /dev/null +++ b/routes/includes/index.js @@ -0,0 +1,9 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + + +module.exports = routes; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..695e6c4 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,24 @@ +const routes = require('express').Router(); + +const about = require('./about'); +routes.use('/about', about); + +const contact = require('./contact'); +routes.use('/contact', contact); + +const projects = ["/steam/"]; + + +routes.get('/', (request, result) => +{ + //blog home +}); + + +routes.get('*', (request, result) => +{ + //error +}); + + +module.exports = routes; \ No newline at end of file diff --git a/routes/projects/index.js b/routes/projects/index.js new file mode 100644 index 0000000..973d8ec --- /dev/null +++ b/routes/projects/index.js @@ -0,0 +1,8 @@ +const routes = require('express').Router(); + +routes.post('/', (request, result) => +{ + +}); + +module.exports = routes; \ No newline at end of file diff --git a/server.js b/server.js index 9bcac45..7e8ea56 100644 --- a/server.js +++ b/server.js @@ -11,12 +11,6 @@ const config = require('./utils/configLoader').getConfig(); /** Port for the server to run on */ const port = config.PORT; -/** http server */ -const http = require('http'); - -/** used to parse the request URL */ -const url = require('url'); - /** express app */ const express = require("express"); @@ -42,62 +36,67 @@ const session = require('express-session'); app.use(session({ secret: config.SESSION_SECRET, cookie: { maxAge: 6000000 }})); -const projects = ["/steam/"]; -/** - * 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(); - } -}); + +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()); -http.createServer(app).listen(port); \ No newline at end of file +app.listen(port, () => + console.log(`App listening on port ${port}!`) +); \ No newline at end of file