Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>>>>>>>>>>>>>>>>>>>>>>>>> db-connection.js
- var mysql = require('mysql');
- var connection = mysql.createPool({
- host: 'localhost',
- user: 'root',
- password: '',
- database: 'movie_review'
- })
- module.exports = connection;
- >>>>>>>>>>>>>>>>>>>>>>>>> moviesDB.js
- "use strict";
- //This is to get the connection to the database
- var db = require('../db-connection'); //reference of db-connection.js
- class MoviesDB
- {
- getAllMovies(callback)
- {
- var sql = "SELECT * FROM movie_review.movie";
- //This is to call the built-in query function in the database connection
- db.query(sql,callback);
- }
- }
- module.exports = MoviesDB;
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> routeMovies.js
- "use strict";
- const movieController = require('../controllers/movieController');
- function routeMovies (app)
- {
- //When the URl is http://localhost:8080/movies, and when HTTP
- //GET method is requested from the cloient, the get() function will
- // be used to call the getAllMovies() function in the controller.
- //The HTTP GET method is called in the getMovieData() function in
- //movies.js. The codes the called it is (open the movies.js file to see):
- // var request = new XMLHttpRequest();
- // request.open('GET', movie_url, true);
- app.route('/movies')
- .get(movieController.getAllMovies);
- }
- module.exports = { routeMovies };
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> movieController.js
- "use strict";
- const MoviesDB = require('../models/MoviesDB');
- var moviesDB = new MoviesDB();
- function getAllMovies(request, respond)
- {
- //Call the getAllMovies() function in the MoviesDB class.
- moviesDB.getAllMovies(function(error, result)
- {
- if (error){
- respond.json(error);
- }
- else {
- respond.json(result);
- }
- });
- }
- module.exports = { getAllMovies };
- >>>>>>>>>>>>>>>>>>>>>>>> server.js
- "use strict";
- const express = require("express");
- const routeMovies = require('./routes/routeMovies');
- const bodyParser = require("body-parser");
- var app = express();
- var host = "127.0.0.1";
- var port = 8080;
- var startPage = "index.html";
- app.use(express.static("./public"));
- app.use(bodyParser.urlencoded({ extended: true }));
- app.use(bodyParser.json());
- routeMovies.routeMovies(app);
- function gotoIndex(req, res) {
- console.log(req.params);
- res.sendFile(__dirname + "/" + startPage);
- }
- app.get("/" + startPage, gotoIndex);
- app.route("/");
- var server = app.listen(port, host, function() {
- var host = server.address().address;
- var port = server.address().port;
- console.log("Example app listening at http://%s:%s", host, port);
- });
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> app.js
- //var movie_url = "https://api.mlab.com/api/1/databases/jobs/collections/movies?apiKey=V0HsJe9lC8Q7naTJK7kS3ZfKnLJdrbQg&s=%7B%27availability%27:1%7D";
- var movie_url = "/movies";
- var movie_array = []; // This creates an empty movie array
- var movieCount = 0;
- var currentIndex = 0;
- /* There are two categories: " Now Showing" and "Coming Soon". This variable states which
- category of movies should be listed when the home page is first loaded. */
- var category = "Now Showing";
- var remote_comment = "https://api.mlab.com/api/1/databases/jobs/collections/comments";
- //API key needed by Cloud DB API
- var remote_api_key = "?apiKey=V0HsJe9lC8Q7naTJK7kS3ZfKnLJdrbQg&s={'datePosted':-1}";
- var comment_url = remote_comment + remote_api_key;
- var comment_array = []; // This creates an empty comment array
- var popcornBWImage = 'images/popcorn_bw.png';
- var popcornImage = 'images/popcorn.png';
- var rating = 0;
- //This function is to display a modal
- //whenever the user clicks on "About" link on the nav bar
- function showAbout() {
- var messageModal = new Modal(document.getElementById("messageModal"));
- document.getElementById("message").innerHTML = "This is an academic website teaching students on fundamentals of various web technologies such as CSS, HTML, Javascript and Restful Web APIs<br><br>Please use Firefox or Chrome";
- document.getElementById("nowMenu").classList.remove("active");
- document.getElementById("comingMenu").classList.remove("active");
- document.getElementById("aboutMenu").classList.add("active");
- messageModal.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement