-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathserver.js
42 lines (36 loc) · 921 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const express = require('express');
const bodyParser = require('body-parser');
const CORS = require('cors');
const app = express();
app.use(bodyParser.json());
app.use(CORS());
const movies = [
{
title: 'The Godfather',
director: 'Francis Ford Coppola',
metascore: 100,
stars: ['Marlon Brando', 'Al Pacino', 'Robert Duvall'],
},
{
title: 'Star Wars',
director: 'George Lucas',
metascore: 92,
stars: ['Mark Hamill', 'Harrison Ford', 'Carrie Fisher'],
},
{
title: 'The Lord of the Rings: The Fellowship of the Ring',
director: 'Peter Jackson',
metascore: 92,
stars: ['Elijah Wood', 'Ian McKellen', 'Orlando Bloom'],
},
];
app.get('/movies', (req, res) => {
res.send(movies);
});
app.get('/movies/:id', (req, res) => {
const movie = movies.filter(movie => movie.id === req.params.id)[0];
res.send(movie);
});
app.listen(5091, () => {
console.log('Server listening on port 5091');
});