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.

56 lines
1.1 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)
  37. {
  38. result.writeHead(200, {'Content-Type': 'text/css'});
  39. utils.include("./" + path).then(function(content)
  40. {
  41. result.write(content);
  42. result.end();
  43. }).catch(function(error)
  44. {
  45. console.log(error);
  46. });
  47. }
  48. };