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.

61 lines
1.5 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. var urlSplit = filename.split("/");
  27. console.log(urlSplit);
  28. if(urlSplit.length >= 2 && urlSplit[1] === 'category') //single category page
  29. file = "./posts/category.js";
  30. else if(urlSplit.length >= 2 && urlSplit[1] === 'admin') //top secret admin page
  31. file = "./admin/admin.js";
  32. else if(urlSplit.length >= 3)//single post page
  33. file = "./posts/posts.js";
  34. else //single static page?
  35. file = "./posts/pages.js";
  36. console.log(file);
  37. includes.printHeader(res).then(function()
  38. {
  39. return require(file).main(res, filename, request);
  40. }).then(function()
  41. {
  42. return includes.printFooter(res);
  43. }).then(function()
  44. {
  45. console.log("fin"); //for debugging
  46. })
  47. }
  48. }).listen(8080);