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.

65 lines
1.4 KiB

  1. /**
  2. * @author Jeffery Russell 8-19-18
  3. */
  4. //used for file IO
  5. const utils = require('../utils/utils.js');
  6. //used for static files
  7. const includes = require('../includes/includes');
  8. //for parsing post data
  9. const qs = require('querystring');
  10. const processContactPage = function(request)
  11. {
  12. return new Promise(function(resolve, reject)
  13. {
  14. utils.getPostData(request).then(function(postData)
  15. {
  16. const data = qs.parse(postData);
  17. console.log(postData);
  18. console.log(data);
  19. if(data.name && data.email)
  20. {
  21. //send email
  22. resolve(utils.include("includes/messageSent.html"));
  23. }
  24. else
  25. {
  26. resolve(utils.include("includes/contact.html"));
  27. }
  28. }).catch(function(err)
  29. {
  30. reject(err);
  31. })
  32. });
  33. };
  34. module.exports =
  35. {
  36. main: function(request, result)
  37. {
  38. result.writeHead(200, {'Content-Type': 'text/html'});
  39. Promise.all([includes.printAdminHeader(),
  40. processContactPage(request),
  41. require("../sidebar/sidebar.js").main(),
  42. includes.printFooter()]).then(function(content)
  43. {
  44. result.write(content.join(''));
  45. result.end();
  46. }).catch(function(err)
  47. {
  48. console.log(err);
  49. });
  50. }
  51. };