Browse Source

Created files for the routes used in this project.

pull/61/head
jrtechs 5 years ago
parent
commit
a937a97f41
15 changed files with 218 additions and 58 deletions
  1. +1
    -0
      package.json
  2. +14
    -0
      routes/about.js
  3. +8
    -0
      routes/admin/analytics.js
  4. +8
    -0
      routes/admin/downloads.js
  5. +35
    -0
      routes/admin/index.js
  6. +8
    -0
      routes/admin/login.js
  7. +8
    -0
      routes/admin/posts.js
  8. +8
    -0
      routes/admin/users.js
  9. +8
    -0
      routes/category/index.js
  10. +13
    -0
      routes/contact.js
  11. +9
    -0
      routes/downloads/index.js
  12. +9
    -0
      routes/includes/index.js
  13. +24
    -0
      routes/index.js
  14. +8
    -0
      routes/projects/index.js
  15. +57
    -58
      server.js

+ 1
- 0
package.json View File

@ -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"
},

+ 14
- 0
routes/about.js View File

@ -0,0 +1,14 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
routes.get('*', (request, result) =>
{
//error
});
module.exports = routes;

+ 8
- 0
routes/admin/analytics.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 8
- 0
routes/admin/downloads.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 35
- 0
routes/admin/index.js View File

@ -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;

+ 8
- 0
routes/admin/login.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 8
- 0
routes/admin/posts.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 8
- 0
routes/admin/users.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 8
- 0
routes/category/index.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 13
- 0
routes/contact.js View File

@ -0,0 +1,13 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
routes.get('*', (request, result) =>
{
//error
});
module.exports = routes;

+ 9
- 0
routes/downloads/index.js View File

@ -0,0 +1,9 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 9
- 0
routes/includes/index.js View File

@ -0,0 +1,9 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 24
- 0
routes/index.js View File

@ -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;

+ 8
- 0
routes/projects/index.js View File

@ -0,0 +1,8 @@
const routes = require('express').Router();
routes.post('/', (request, result) =>
{
});
module.exports = routes;

+ 57
- 58
server.js View File

@ -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);
app.listen(port, () =>
console.log(`App listening on port ${port}!`)
);

Loading…
Cancel
Save