-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (30 loc) · 1.15 KB
/
index.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'), http = require('http');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const dishRouter = require('./routes/dishRouter');
const hostname = 'localhost';
const port = 3000;
const app = express();
app.use(morgan('dev'));
app.use(express.static(__dirname + './public'));
app.use(bodyParser.json());
app.use('/dishes', dishRouter);
app.get('/dishes/:dishId', (req, res, next) => {
res.end('Will send details of the dish: ' + req.params.dishId + ' to you!');
});
app.post('/dishes/:dishId', (req, res, next) => {
res.statusCode = 403;
res.end('POST operation not supported on /dishes/' + req.params.dishId);
});
app.put('/dishes/:dishId', (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', (req, res, next) => {
res.end('Deleting dish: ' + req.params.dishId);
});
const server = http.createServer(app);
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});