This commit is contained in:
Nikola Petrov 2023-08-02 14:27:35 +02:00
parent 96099f751b
commit f240d4e7c5
12 changed files with 164 additions and 191 deletions

30
app.js
View File

@ -27,13 +27,6 @@ var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:')); db.on('error', console.error.bind(console, 'MongoDB connection error:'));
var oldRouter = require('./routes/main/1_0');
var newRouter = require('./routes/main/2_0');
var listRouter = require('./routes/list');
var photosRouter = require('./routes/api/photoRouter');
var movieRouter = require('./routes/api/movieRouter');
var mailRouter = require('./routes/mail');
var app = express(); var app = express();
const httpServer = http.createServer(app); const httpServer = http.createServer(app);
@ -49,20 +42,6 @@ app.use(express.urlencoded({ extended: false }));
app.use(cookieParser()); app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
/**
* Vključimo session in connect-mongo.
* Connect-mongo skrbi, da se session hrani v bazi.
* Posledično ostanemo prijavljeni, tudi ko spremenimo kodo (restartamo strežnik)
*/
var session = require('express-session');
var MongoStore = require('connect-mongo');
app.use(session({
secret: 'work hard',
resave: true,
saveUninitialized: false,
store: MongoStore.create({ mongoUrl: mongoDB })
}));
//Shranimo sejne spremenljivke v locals //Shranimo sejne spremenljivke v locals
//Tako lahko do njih dostopamo v vseh view-ih (glej layout.hbs) //Tako lahko do njih dostopamo v vseh view-ih (glej layout.hbs)
app.use(function (req, res, next) { app.use(function (req, res, next) {
@ -70,10 +49,13 @@ app.use(function (req, res, next) {
next(); next();
}); });
var mainRouter = require('./routes/main');
var listRouter = require('./routes/list');
var photosRouter = require('./routes/api/photoRouter');
var movieRouter = require('./routes/api/movieRouter');
var mailRouter = require('./routes/mail');
app.use('/', mainRouter);
app.use('/', newRouter);
app.use('/old', oldRouter);
app.use('/list', listRouter); app.use('/list', listRouter);
app.use('/api/photos', photosRouter); app.use('/api/photos', photosRouter);
app.use('/api/movies', movieRouter); app.use('/api/movies', movieRouter);

View File

@ -55,7 +55,6 @@ module.exports = {
title: mData.Title, title: mData.Title,
released: mData.Released, released: mData.Released,
webImg: mData.Poster, webImg: mData.Poster,
genre: mData.Genre
}); });
const savedMovie = await movie.save(); const savedMovie = await movie.save();
@ -72,8 +71,7 @@ module.exports = {
var id = req.body.code; var id = req.body.code;
const passp = req.body.pass; const passp = req.body.pass;
try try {
{
const userFound = await UserModel.findOne({ pass: passp }); const userFound = await UserModel.findOne({ pass: passp });
if (!userFound) { if (!userFound) {
return res.status(404).json({ message: 'Wrong password' }); return res.status(404).json({ message: 'Wrong password' });
@ -86,8 +84,7 @@ module.exports = {
return res.status(204).json(); return res.status(204).json();
} }
catch(err) catch (err) {
{
return res.status(500).json({ message: 'Error when deleting the movie.' }); return res.status(500).json({ message: 'Error when deleting the movie.' });
} }
}, },

View File

@ -5,7 +5,6 @@ var movieSchema = new Schema({
'title': String, 'title': String,
'released': String, 'released': String,
'webImg': String, 'webImg': String,
'genre' : String,
'code': String 'code': String
}); });

13
routes/main.js Normal file
View File

@ -0,0 +1,13 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function (req, res, next) {
res.render('main/2_0', { title: 'Nikola Petrov', disableBootStrap: true });
});
router.get('/old', function (req, res, next) {
res.render('main/1_0', { title: 'Nikola Petrov' });
});
module.exports = router;

View File

@ -1,9 +0,0 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('main/1_0', {title:'Nikola Petrov'});
});
module.exports = router;

View File

@ -1,9 +0,0 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('main/2_0', {title:'Nikola Petrov', disableBootStrap: true});
});
module.exports = router;