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.

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