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.3 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(result)
  18. {
  19. result.writeHead(200, {'Content-Type': 'text/html'});
  20. return utils.include(result, HEADER_FILE);
  21. },
  22. /**
  23. * Appends the footer to the result object
  24. *
  25. * @param result
  26. * @return {*|Promise}
  27. */
  28. printFooter: function(result)
  29. {
  30. return new Promise(function(resolve, reject)
  31. {
  32. utils.include(result, FOOTER_FILE).then(function()
  33. {
  34. result.end();
  35. resolve();
  36. })
  37. })
  38. },
  39. /**Sends a css file to the user
  40. *
  41. * @param result
  42. * @param path
  43. * @return {*}
  44. */
  45. sendCSS: function(result, path)
  46. {
  47. result.writeHead(200, {'Content-Type': 'text/css'});
  48. utils.include(result, "./" + path);
  49. result.end();
  50. }
  51. };