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.

58 lines
1.7 KiB

  1. //sending static content
  2. const includes = require('../includes/includes.js');
  3. //used for file IO
  4. const utils = require('../utils/utils.js');
  5. //used to append static content to result
  6. const contentLoader = require('../includes/staticContentServer.js');
  7. const whiskers = require('whiskers');
  8. /**
  9. * @author Jeffery Russell 11-3-18
  10. *
  11. * @type {{main: (function(*=, *): Promise)}}
  12. */
  13. module.exports=
  14. {
  15. /**
  16. * Calls posts and sidebar modules to render blog contents in order
  17. *
  18. * @param requestURL
  19. * @returns {Promise|*}
  20. */
  21. main: function(request, result, filename)
  22. {
  23. if(contentLoader.serveStaticContent(request, result, filename, ""))
  24. {
  25. //do nothing
  26. }
  27. else
  28. {
  29. const clientAddress = (request.headers['x-forwarded-for'] || '').split(',')[0]
  30. || request.connection.remoteAddress;
  31. result.writeHead(200, {'Content-Type': 'text/html'});
  32. const file = "../admin/admin.js";
  33. var templateContext = Object();
  34. Promise.all([includes.printAdminHeader(templateContext),
  35. require(file).main(request, clientAddress, templateContext),
  36. includes.printFooter(templateContext),
  37. includes.fetchTemplate("admin/adminMain.html")]).then(function(content)
  38. {
  39. result.write(whiskers.render(content.join(''), templateContext));
  40. result.end();
  41. }).catch(function(err)
  42. {
  43. console.log(err);
  44. throw err;
  45. });
  46. }
  47. }
  48. };