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');
7 var indexRouter = require('./routes/index');
8 var usersRouter = require('./routes/users');
13 app.set('views', path.join(__dirname, 'views'));
14 app.set('view engine', 'ejs');
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')));
22 app.use('/public/stylesheets', express.static('stylesheets'));
23 app.use('/public/images', express.static('images'));
24 app.use('/public/javascripts', express.static('javascripts'));
27 app.use('/', indexRouter);
28 app.use('/users', usersRouter);
30 // catch 404 and forward to error handler
31 app.use(function(req, res, next) {
32 next(createError(404));
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 : {};
41 // render the error page
42 res.status(err.status || 500);