Personal blog written from scratch using Node.js, Bootstrap, and MySQL. https://jrtechs.net
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.3 KiB

  1. /**
  2. * Main server file for the blog. This file is responsible for
  3. * creating the server and listening for clients. The main run
  4. * function parses the url and calls a sub module to make the
  5. * appropriate pages.
  6. */
  7. const http = require('http');
  8. const url = require('url');
  9. const includes = require('./includes/includes.js');
  10. http.createServer(function (request_url, res)
  11. {
  12. var q = url.parse(request_url.url, true);
  13. var filename = q.pathname;
  14. console.log(filename.split("/"));
  15. console.log(filename);
  16. //prints header
  17. //handles image requests
  18. if(filename.includes("/img/"))
  19. {
  20. require("./img/image.js").main(res, filename);
  21. }
  22. else
  23. {
  24. includes.printHeader(res);
  25. //categories or view a category page
  26. if(filename.includes("/category"))
  27. require("../posts/category.js").main(res, filename);
  28. //downloads page
  29. else if(filename.includes("/downloads/"))
  30. {}
  31. //admin page
  32. else if(filename.includes("/admin"))
  33. require("./admin/admin.js").main(res, filename);
  34. //normal blog entry
  35. else
  36. require("./posts/posts.js").main(res, filename);
  37. //includes footer file
  38. includes.printFooter(res);
  39. }
  40. }).listen(8080);