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.

57 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. console.log(FOOTER_FILE);
  33. utils.include(result, FOOTER_FILE).then(function()
  34. {
  35. result.end();
  36. resolve();
  37. })
  38. })
  39. },
  40. /**Sends a css file to the user
  41. *
  42. * @param result
  43. * @param path
  44. * @return {*}
  45. */
  46. sendCSS: function(result, path)
  47. {
  48. result.writeHead(200, {'Content-Type': 'text/css'});
  49. utils.include(result, "./" + path);
  50. result.end();
  51. }
  52. };