-
Notifications
You must be signed in to change notification settings - Fork 10
/
server.js
45 lines (35 loc) · 1.17 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
const express = require('express'),
bodyParser = require('body-parser'),
morgan = require('morgan'),
helmet = require('helmet'),
addRequestId = require('express-request-id')(),
config = require('./config'),
routes = require('./routes/films'),
app = express();
//Logger
//@see: https://medium.com/@tobydigz/logging-in-a-node-express-app-with-morgan-and-bunyan-30d9bf2c07a
const loggerFormat = ':id [:date[web]] ":method :url" :status :response-time ms';
app.use(addRequestId);
morgan.token('id', req => req.id);
app.use(morgan(loggerFormat, {
skip: (req, res) => res.statusCode < 400,
stream: process.stderr
}));
app.use(morgan(loggerFormat, {
skip: (req, res) => res.statusCode >= 400,
stream: process.stdout
}));
//Middelware
app.use(helmet());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('public'));
app.set('view engine', 'pug');
//Rutas
app.get('/', routes.getAllFilms);
app.get('/create/:name', routes.createFilm);
app.get('/film/:id', routes.getFilm);
app.post('/film/:id/delete', routes.destroyFilm);
app.post('/film/:id/update',routes.updateFilm);
// Puerto
app.listen(config.port);