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.

37 lines
784 B

  1. const routes = require('express').Router();
  2. const sql = require('../../utils/sql');
  3. const renderPost = require('../../blog/renderBlogPost');
  4. routes.get('/posts', (request, result) =>
  5. {
  6. sql.getAllPosts().then((data)=>
  7. {
  8. result.json(data).end();
  9. }).catch((err)=>
  10. {
  11. result.status(500).json([]).end();
  12. });
  13. });
  14. routes.get('/render/:postID', (request, result) =>
  15. {
  16. sql.getPostById(request.params.postID).then((sqlData)=>
  17. {
  18. renderPost.generateBlogPost(sqlData, -1).then((rendered)=>
  19. {
  20. result.json(rendered).end();
  21. });
  22. }).catch((err)=>
  23. {
  24. result.status(404).json({error: 404}).end();
  25. })
  26. });
  27. routes.get('*', (request, result) =>
  28. {
  29. result.json([]).end();
  30. });
  31. module.exports = routes;