-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
51 lines (45 loc) · 1.18 KB
/
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
43
44
45
46
47
48
49
50
// APP REQUIREMENTS
require('dotenv').config();
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const PORT = process.env.PORT;
var db = require('./database.js');
//ROUTES
app.use(express.static('client'));
app.use(express.static('node_modules'));
app.use(bodyParser.urlencoded({ 'extended': 'true' }));
app.use(bodyParser.json());
app.get('/shelf', function (req, res) {
db.selectAll(function (err, data) {
if (err) {
res.sendStatus(500);
} else {
res.json(data);
}
});
});
app.post('/shelf', function (req, res) {
//console.log(req.body);
db.add(req.body.params.movie, function (err, res) {
if (err) {
res.sendStatus(500);
} else {
res.end("movie on the shelf!");
}
});
});
app.delete("/shelf", function (req, res) {
console.log(req.body);
db.remove(req.body.movieId, function (err) {
if (err) {
res.sendStatus(404);
} else {
res.end("that was rotten anyways!");
}
});
});
//NOW LISTEN
app.listen(PORT, (err) => {
console.log(err || `listening on port ${PORT}`);
});