Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated index.js file #7

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
const express = require("express");
const morgan = require("morgan");
const app = express();
const port = 8080;

// Middleware to log all requests
app.use(morgan("combined"));

// GET route for /movies
app.get("/movies", (req, res) => {
// JSON object containing data about the top 10 movies
const movies = [
{ title: "Movie 1", rating: 8 },
{ title: "Movie 2", rating: 7 },
{ title: "Movie 3", rating: 9 },
{ title: "Movie 4", rating: 8 },
{ title: "Movie 5", rating: 8 },
{ title: "Movie 6", rating: 7 },
{ title: "Movie 7", rating: 9 },
{ title: "Movie 8", rating: 6 },
{ title: "Movie 9", rating: 7 },
{ title: "Movie 10", rating: 8 },
];

res.json(movies);
});

// GET route for /
app.get("/", (req, res) => {
res.send("Welcome to my movies website!");
});

// Serve the documentation.html file
app.use(express.static("public"));

// Error handling middleware
app.use((err, req, res, next) => {
console.error(err);
res.status(500).send("Internal Server Error");
});

// Start the server
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});