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.

62 lines
1.8 KiB

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