-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (37 loc) · 1.31 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
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var hostname = 'localhost';
var port = 3000;
var app = express();
app.use(morgan('dev'));
app.use(bodyParser.json());
app.all('/dishes', function(req,res,next) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
next();
});
app.get('/dishes', function(req,res,next){
res.end('Will send all the dishes to you!');
});
app.post('/dishes', function(req, res, next){
res.end('Will add the dish: ' + req.body.name + ' with details: ' + req.body.description);
});
app.delete('/dishes', function(req, res, next){
res.end('Deleting all dishes');
});
app.get('/dishes/:dishId', function(req,res,next){
res.end('Will send details of the dish: ' + req.params.dishId +' to you!');
});
app.put('/dishes/:dishId', function(req, res, next){
res.write('Updating the dish: ' + req.params.dishId + '\n');
res.end('Will update the dish: ' + req.body.name +
' with details: ' + req.body.description);
});
app.delete('/dishes/:dishId', function(req, res, next){
res.end('Deleting dish: ' + req.params.dishId);
});
app.use(express.static(__dirname + '/public'));
app.listen(port, hostname, function(){
//noinspection JSAnnotator
console.log(`Server running at http://${hostname}:${port}/`);
});