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.

66 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. if(fullPath.charAt(0) === '/')
  14. fullPath = fullPath.substring(1,);
  15. if (filename.includes(".svg") || filename.includes(".svg"))
  16. {
  17. includes.sendSVG(result, fullPath);
  18. return true;
  19. }
  20. //handles image requests
  21. else if (filename.includes(".jpg") ||
  22. filename.includes(".png") || filename.includes(".ico"))
  23. {
  24. includes.sendImage(result, fullPath);
  25. return true;
  26. }
  27. else if (filename.includes(".pdf"))
  28. {
  29. includes.sendPDF(result, fullPath);
  30. return true;
  31. }
  32. //css and font files
  33. else if (filename.includes(".woff2") || filename.includes(".css") ||
  34. filename.includes(".txt"))
  35. {
  36. includes.sendCSS(result, fullPath);
  37. return true;
  38. }
  39. else if (filename.includes(".json"))
  40. {
  41. if(fullPath.includes("includes/") || fullPath.includes("blogContent"))
  42. {
  43. includes.sendHTML(result, fullPath);
  44. return true;
  45. }
  46. }
  47. //scripts
  48. else if (filename.includes(".js"))
  49. {
  50. if(fullPath.includes("includes/") || fullPath.includes("blogContent"))
  51. {
  52. includes.sendJS(result, fullPath);
  53. return true;
  54. }
  55. }
  56. //html
  57. else if (filename.includes(".html"))
  58. {
  59. includes.sendHTML(result, fullPath);
  60. return true;
  61. }
  62. return false;
  63. }
  64. };