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.

35 lines
880 B

  1. var express = require('express');
  2. let res = require('express/lib/response');
  3. var router = express.Router();
  4. let blog = [];
  5. /* GET home page. */
  6. router.route('/')
  7. .get((req, res, next) => { // => Pfeilfunktion: ersetzt function()
  8. res.send({ blog });
  9. })
  10. .post((req, res, next) => {
  11. let blogeintrag = [];
  12. let title = req.body.title;
  13. let username = req.body.username;
  14. let date = req.body.date;
  15. let text = req.body.text;
  16. console.log(title);
  17. blogeintrag.push(title, username, date, text);
  18. blog.push(blogeintrag);
  19. res.render('blogPost', { title: 'Nächster Post' })
  20. });
  21. router.get('/newPost', function (req, res, next) {
  22. res.render('blogPost', { title: 'BlogEintrag' });
  23. });
  24. router.get('/:id', function (req, res, next) {
  25. let blogID = req.params.id;
  26. console.log(blogID);
  27. res.send(blog[blogID]);
  28. });
  29. module.exports = router;