Loading dynamic content on the homepage
Currently, our homepage has all the static movies in the content. Let's fill the data with the data that we have added to the movies in our database. For that, the first thing to do is to add a few movies to the database, which we can do via the http://localhost:8080/movies/add
endpoint from the UI.
API endpoint to fetch all movies
First, we need to add an endpoint to fetch all the movies from the Mongo database. So, let's first add an endpoint to fetch all the movies in controllers/movies.js
:
const MovieSchema = require('../models/Movie.js'); module.exports.controller = (app) => { // fetch all movies app.get('/movies', (req, res) => { MovieSchema.find({}, 'name description release_year genre', (error, movies) => { if (error) { console.log(error); } res.send({ movies, }); }); }); // add a new movie app.post('/movies', (req, res) => { const newMovie = new MovieSchema({ name: req.body.name...