Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. var express = require( 'express'),
  2. bodyParser = require( 'body-parser'),
  3. app = express();
  4.  
  5. app.use( bodyParser.urlencoded( { extended: true} ) );
  6. app.use( bodyParser.json() );
  7.  
  8. var posts = [
  9. { title: "Топик1", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" },
  10. { title: "Топик2", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" },
  11. { title: "Топик3", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" },
  12. { title: "Топик4", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" }
  13. ];
  14. app.get( "/", function ( req, res ) {
  15. res.render( 'index.ejs', { posts: posts } );
  16. } );
  17.  
  18. app.get( "/post/:id", function ( req, res) {
  19. var id = req.params.id;
  20. res.render( 'post.ejs', { post: posts[id - 1] } );
  21. });
  22.  
  23. app.get( '/write', function ( req, res) {
  24. res.render( 'write.ejs' );
  25. });
  26.  
  27. app.post( '/write', function ( req, res ) {
  28. var
  29. title = req.body.title,
  30. content = req.body.content;
  31.  
  32. post.push( { title: title, content: content } );
  33.  
  34. res.redirect( '/' );
  35. } );
  36. app.listen( 3000, function() {
  37. console.log( "Work on port: 3000");
  38. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement