comienzo del trabajo del header
[projectNeoUtesa/.git] / app.js
1 var createError = require('http-errors');
2 var express = require('express');
3 var path = require('path');
4 var cookieParser = require('cookie-parser');
5 var logger = require('morgan');
6
7 var indexRouter = require('./routes/index');
8 var usersRouter = require('./routes/users');
9
10 var app = express();
11
12 // view engine setup
13 app.set('views', path.join(__dirname, 'views'));
14 app.set('view engine', 'ejs');
15
16 app.use(logger('dev'));
17 app.use(express.json());
18 app.use(express.urlencoded({ extended: false }));
19 app.use(cookieParser());
20 app.use(express.static(path.join(__dirname, 'public')));
21 //setup places
22 app.use('/public/stylesheets', express.static('stylesheets'));
23 app.use('/public/images', express.static('images'));
24 app.use('/public/javascripts', express.static('javascripts'));
25 app.use('/favicon.ico', express.static('/public/images/favicon.ico'));
26
27 app.use('/', indexRouter);
28 app.use('/users', usersRouter);
29
30 // catch 404 and forward to error handler
31 app.use(function(req, res, next) {
32   next(createError(404));
33 });
34
35 // error handler
36 app.use(function(err, req, res, next) {
37   // set locals, only providing error in development
38   res.locals.message = err.message;
39   res.locals.error = req.app.get('env') === 'development' ? err : {};
40
41   // render the error page
42   res.status(err.status || 500);
43   res.render('error');
44 });
45
46 module.exports = app;