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.2 KiB

  1. //http server
  2. const http = require('http');
  3. //used to parse the request URL
  4. const url = require('url');
  5. //express app
  6. const express = require("express");
  7. //express app
  8. const app = express();
  9. //used to append static content to result
  10. const includes = require('./includes/includes.js');
  11. //used to append static content to result
  12. const contentLoader = require('./includes/staticContentServer.js');
  13. //port for the server to run on
  14. const port = 8000;
  15. /**
  16. * Parses the request url and calls correct JS files
  17. */
  18. app.use(function(request, result)
  19. {
  20. const filename = url.parse(request.url, true).pathname;
  21. if(contentLoader.serveStaticContent(request, result, filename, ""))
  22. {
  23. //do nothing
  24. }
  25. else
  26. {
  27. result.writeHead(200, {'Content-Type': 'text/html'});
  28. Promise.all([includes.printHeader(),
  29. require('./blog/renderBlogPost.js').generateBlogPostComponent('/programming/', 'cs-theory-exam-2-review', -1),
  30. includes.printFooter()]).then(function (content)
  31. {
  32. result.write(content.join(''));
  33. result.end();
  34. }).catch(function (err)
  35. {
  36. console.log(err);
  37. throw err;
  38. });
  39. }
  40. });
  41. http.createServer(app).listen(port);