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.

54 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, res)
  11. {
  12. var q = url.parse(request.url, true);
  13. var filename = q.pathname;
  14. //handles image requests
  15. if(filename.includes("/img/"))
  16. {
  17. require("./img/image.js").main(res, filename);
  18. }
  19. else if(filename.includes("/css/"))
  20. {
  21. includes.sendCSS(res, filename)
  22. }
  23. else
  24. {
  25. var file = "";
  26. if(filename.includes("/categories/")) //single category page
  27. file = "./posts/category.js";
  28. else if(filename.includes("/admin")) //top secret admin page
  29. file = "./admin/admin.js";
  30. else //single post page
  31. file = "./posts/posts.js";
  32. console.log(file);
  33. includes.printHeader(res).then(function()
  34. {
  35. return require(file).main(res, filename, request);
  36. }).then(function()
  37. {
  38. return includes.printFooter(res);
  39. }).then(function()
  40. {
  41. console.log("fin"); //for debugging
  42. })
  43. }
  44. }).listen(8080);