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.

61 lines
1.9 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. //css and font files
  28. else if (filename.includes(".woff2") || filename.includes(".css") ||
  29. filename.includes(".txt"))
  30. {
  31. includes.sendCSS(result, fullPath);
  32. return true;
  33. }
  34. else if (filename.includes(".json"))
  35. {
  36. if(fullPath.includes("includes/") || fullPath.includes("blogContent"))
  37. {
  38. includes.sendHTML(result, fullPath);
  39. return true;
  40. }
  41. }
  42. //scripts
  43. else if (filename.includes(".js"))
  44. {
  45. if(fullPath.includes("includes/") || fullPath.includes("blogContent"))
  46. {
  47. includes.sendJS(result, fullPath);
  48. return true;
  49. }
  50. }
  51. //html
  52. else if (filename.includes(".html"))
  53. {
  54. includes.sendHTML(result, fullPath);
  55. return true;
  56. }
  57. return false;
  58. }
  59. };