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.

68 lines
2.1 KiB

  1. //used to append static content to result
  2. const includes = require('../includes/includes.js');
  3. /**
  4. * @author Jeffery Russell 10-30-18
  5. *
  6. * @type {{main: (function(*=, *): Promise)}}
  7. */
  8. module.exports=
  9. {
  10. serveStaticContent: function(request, result, filename, baseURL)
  11. {
  12. var fullPath = baseURL + filename;
  13. var filename = filename.toLowerCase();
  14. if(fullPath.charAt(0) === '/')
  15. fullPath = fullPath.substring(1,);
  16. if (filename.includes(".svg") || filename.includes(".svg"))
  17. {
  18. includes.sendSVG(result, fullPath);
  19. return true;
  20. }
  21. //handles image requests
  22. else if (filename.includes(".jpg") ||
  23. filename.includes(".png") || filename.includes(".ico"))
  24. {
  25. includes.sendImage(result, fullPath);
  26. return true;
  27. }
  28. else if (filename.includes(".pdf"))
  29. {
  30. includes.sendPDF(result, fullPath);
  31. return true;
  32. }
  33. //css and font files
  34. else if (filename.includes(".woff2") || filename.includes(".css") ||
  35. filename.includes(".txt"))
  36. {
  37. includes.sendCSS(result, fullPath);
  38. return true;
  39. }
  40. else if (filename.includes(".json"))
  41. {
  42. if(fullPath.includes("includes/") || fullPath.includes("blogContent"))
  43. {
  44. includes.sendHTML(result, fullPath);
  45. return true;
  46. }
  47. }
  48. //scripts
  49. else if (filename.includes(".js"))
  50. {
  51. if(fullPath.includes("includes/") || fullPath.includes("blogContent"))
  52. {
  53. includes.sendJS(result, fullPath);
  54. return true;
  55. }
  56. }
  57. //html
  58. else if (filename.includes(".html"))
  59. {
  60. includes.sendHTML(result, fullPath);
  61. return true;
  62. }
  63. return false;
  64. }
  65. };