Untitled
raw download clone
TEXT
views 29
,
size 2622 b
var express = require('express');
var app = express();
var faker = require('faker');
const image = [{image:"https://i.imgur.com/TZjQlRk.jpg"}];

app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/views'));
var bodyParser  = require('body-parser');
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
app.use(express.json());


var album1 = {name: "Pet Sounds", artist: "The Beach Boys", year: 1966, label: "Capitol", coverlink: "https://upload.wikimedia.org/wikipedia/en/b/bb/PetSoundsCover.jpg"};
var album2 = {name: "Long Season", artist: "Fishmans", year: 1996, label: "Polydor", coverlink: "https://upload.wikimedia.org/wikipedia/en/7/7d/Fishmans_Long_Season.jpg"};
var album3 = {name: "Opera Sauvage", artist: "Vangelis", year: 1979, label: "Polydor", coverlink: "https://upload.wikimedia.org/wikipedia/en/6/65/Opera_Sauvage.jpg"};

var Albums = new Array(album1, album2, album3);

app.get('/', function (req, res) {
  res.render('index', );
})
app.get('/index', function (req, res) {
  res.render('index', );
})
app.get('/ranks', function (req, res) {
  res.render('index', );
})
app.get('/add', function (req, res) {
  res.render('add', );
})
app.get('/show', function (req, res) {
  res.render('show', {Albums: Albums});
})
app.get('/about', function (req, res) {
  res.render('about', );
})


app.post('/addreceived', function (req, res) {
    
    var war1 = req.body.album_name;
    var war2 = req.body.album_artist;
    var war3 = req.body.album_year;
    var war4 = req.body.album_label;
    var war5 = req.body.album_coverlink;
    Albums.push({name: war1, artist: war2, year: parseInt(war3), label: war4, coverlink: war5});
    res.render('album_added',);
})


app.post('/delete', function (req, res) {
    var index = req.body.index;
    if (index > -1) {
        Albums.splice(index, 1);
    }

    res.render('show', {Albums: Albums});
})

app.post('/edit', function (req, res) {
    var index = req.body.index;
    res.render('edit', {album: Albums[index], index: index});
})
app.post('/editreceived', function (req, res) {
    var war1 = req.body.album_name;
    var war2 = req.body.album_artist;
    var war3 = req.body.album_year;
    var war4 = req.body.album_label;
    var war5 = req.body.album_coverlink;
    Albums.push({name: war1, artist: war2, year: parseInt(war3), label: war4, coverlink: war5});
    var index = req.body.index;
    if (index > -1) {
        Albums.splice(index, 1);
    }
    res.render('album_added',);
})

app.listen(3000, function(){
    console.log('dziala');
})
close fullscreen
Login or Register to edit or fork this paste. It's free.