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.

48 lines
1.2 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
  20. {
  21. var file = "";
  22. if(filename.includes("/category")) //single category page
  23. file = "../posts/category.js";
  24. else if(filename.includes("/admin")) //top secret admin page
  25. file = "./admin/admin.js";
  26. else //single post page
  27. file = "./posts/posts.js";
  28. includes.printHeader(res).then(function()
  29. {
  30. return require(file).main(res, filename, request);
  31. }).then(function()
  32. {
  33. return includes.printFooter(res);
  34. }).then(function()
  35. {
  36. console.log("fin"); //for debugging
  37. })
  38. }
  39. }).listen(8080);