Building Authentication with passport.js Chapter 6route.controller(app)
}
})
app.use(serveStatic(__dirname + "/dist"));
...With this, let's now build our application with the following command:
$ npm run buildThe preceding command will create the necessary static files inside the dist folder in the
application that will be served by the Node.js server, which is in the 8081 port. After the
build, we now do not need to run the following command:
$ npm run devAlso, now since we will be running our node server only, the application should be
available at the URL http://localhost:8081.
The preceding command starts our frontend server. We only need to run the Node.js server
with the following command:
$ nodemon server.jsSince we now only have one port, 8081, we do not need to add the prefix /api in every
backend API like we did earlier, we can get rid of those as well. So, let's update
the controllers and vue files as well:
Replace the contents in controllers/movies.js, as follows:
var Movie = require("../models/Movie");module.exports.controller = (app) => {
// fetch all movies
app.get("/movies", function(req, res) {
Movie.find({}, 'name description release_year genre', function
(error, movies) {
if (error) { console.log(error); }
res.send({
movies: movies
})
})
})// add a new movie
app.post('/movies', (req, res) => {
const movie = new Movie({