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.

55 lines
1.7 KiB

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