forked from msemenistyi/BSA2014-BackboneJS-underscoreJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
62 lines (52 loc) · 1.54 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var express = require('express'),
app = express(),
bodyParser = require('body-parser'),
filmService = require('./filmService');
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.get('/api/films', function (req, res) {
res.send(filmService.getFilmList());
});
app.get('/api/films/:id', function (req, res) {
var film = filmService.getFilmList(req.params.id);
if (film){
res.send(film);
} else {
res.send('No film with id ' + req.params.id);
}
});
app.delete('/api/films/:id', function (req, res) {
var film = filmService.deleteFilm(req.params.id);
res.end();
});
app.put('/api/films/:id', function (req, res) {
var film = filmService.addFilm(req.params.id);
filmService.addFilm(req.body);
res.status(200);
res.end();
});
app.post('/api/films', function (req, res) {
filmService.addFilm(req.body);
res.status(200);
res.end();
});
app.get('/api/filmdetails/:id', function (req, res) {
res.send(filmService.getFilm(req.params.id));
});
app.get('/', function(req, res){
var text = [
'<b>localhost:3000/api/films</b>',
'returns the list of films available',
'<br />',
'<b>localhost:3000/api/films/%id%</b>',
'where %id% is id of the film from the list',
'<br />',
'<b>localhost:3000/api/filmdetails/%id%</b>',
'where <b>%filmname%</b> is a name of the film from the filmlist',
'<br />',
'<b>localhost:3000/app</b>',
'this is the root of your web app'];
res.send(text.join('<br />'));
});
app.listen(3000);
console.log('Server started on port 3000. Go to localhost:3000 for further instructions');