Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var express = require( 'express'),
- bodyParser = require( 'body-parser'),
- app = express();
- app.use( bodyParser.urlencoded( { extended: true} ) );
- app.use( bodyParser.json() );
- var posts = [
- { title: "Топик1", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" },
- { title: "Топик2", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" },
- { title: "Топик3", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" },
- { title: "Топик4", content: "Текст Текст Текст ТекстТекстТекстТекстТекстТекстТекст" }
- ];
- app.get( "/", function ( req, res ) {
- res.render( 'index.ejs', { posts: posts } );
- } );
- app.get( "/post/:id", function ( req, res) {
- var id = req.params.id;
- res.render( 'post.ejs', { post: posts[id - 1] } );
- });
- app.get( '/write', function ( req, res) {
- res.render( 'write.ejs' );
- });
- app.post( '/write', function ( req, res ) {
- var
- title = req.body.title,
- content = req.body.content;
- post.push( { title: title, content: content } );
- res.redirect( '/' );
- } );
- app.listen( 3000, function() {
- console.log( "Work on port: 3000");
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement