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.

63 lines
2.0 KiB

  1. //file io
  2. const utils = require('../utils/utils.js');
  3. //used to parse the request URL
  4. const url = require('url');
  5. /**
  6. * @author Jeffery Russell 10-30-18
  7. *
  8. * @type {{main: (function(*=, *): Promise)}}
  9. */
  10. module.exports=
  11. {
  12. /**
  13. * Calls posts and sidebar modules to render blog contents in order
  14. *
  15. * @param requestURL
  16. * @returns {Promise|*}
  17. */
  18. main: function(request, result, baseURL)
  19. {
  20. //const filename = url.parse(request.url, true).pathname
  21. var filename = url.parse(request.url, true).pathname;
  22. if(filename.includes(".svg") || filename.includes(".svg"))
  23. {
  24. result.writeHead(200, {'Content-Type': 'image/svg+xml'});
  25. }
  26. else if(filename.includes("/img/") || filename.includes(".jpg") ||
  27. filename.includes(".png") || filename.includes(".ico"))
  28. {
  29. result.writeHead(200, {'Content-Type': 'image/png'});
  30. }
  31. else if(filename.includes("/css/") || filename.includes(".woff2") ||
  32. filename.includes(".txt"))
  33. {
  34. result.writeHead(200, {'Content-Type': 'text/css'});
  35. }
  36. else if(filename.includes("/js/") || filename.includes(".js"))
  37. {
  38. result.writeHead(200, {'Content-Type': 'application/javascript'});
  39. }
  40. else
  41. {
  42. result.writeHead(200, {'Content-Type': 'text/html'});
  43. }
  44. if(filename == baseURL || filename == baseURL.substring(0, baseURL.length - 1))
  45. {
  46. filename = baseURL + "index.html";
  47. }
  48. utils.include("./blogContent/projects" + filename).then(function(content)
  49. {
  50. result.write(content);
  51. result.end();
  52. }).catch(function(error)
  53. {
  54. console.log(error);
  55. });
  56. }
  57. };