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.

67 lines
1.4 KiB

  1. /**
  2. Includes.js
  3. File used for getting the header and footer
  4. */
  5. const utils = require('../utils/utils.js');
  6. const HEADER_FILE = "includes/header.html";
  7. const FOOTER_FILE = "includes/footer.html";
  8. const Promise = require('promise');
  9. module.exports =
  10. {
  11. /** Appends the header html section to the result which is
  12. * sent to the user.
  13. *
  14. * @param result
  15. * @return {*} a promise retrieved from the utils.include function
  16. */
  17. printHeader: function()
  18. {
  19. return utils.include(HEADER_FILE);
  20. },
  21. /**
  22. * Appends the footer to the result object
  23. *
  24. * @return {*|Promise}
  25. */
  26. printFooter: function()
  27. {
  28. return utils.include(FOOTER_FILE);
  29. },
  30. /**Sends a css file to the user
  31. *
  32. * @param result
  33. * @param path
  34. * @return {*}
  35. */
  36. sendCSS: function(result, path, cache)
  37. {
  38. result.writeHead(200, {'Content-Type': 'text/css', 'Cache-Control': 'public, max-age=604800'});
  39. var css = cache.get(path);
  40. if(css == null)
  41. {
  42. utils.include("./" + path).then(function(content)
  43. {
  44. result.write(content);
  45. result.end();
  46. cache.put(path, content);
  47. }).catch(function(error)
  48. {
  49. console.log(error);
  50. });
  51. }
  52. else
  53. {
  54. result.write(css);
  55. result.end();
  56. }
  57. }
  58. };