You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

4 years ago
  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. var indexRouter = require('./routes/index');
  7. var usersRouter = require('./routes/users');
  8. var app = express();
  9. // view engine setup
  10. app.set('views', path.join(__dirname, 'views'));
  11. app.set('view engine', 'ejs');
  12. app.use(logger('dev'));
  13. app.use(express.json());
  14. app.use(express.urlencoded({ extended: false }));
  15. app.use(cookieParser());
  16. app.use(express.static(path.join(__dirname, 'public')));
  17. app.use(require('connect-livereload')());
  18. app.use('/', indexRouter);
  19. app.use('/users', usersRouter);
  20. // catch 404 and forward to error handler
  21. app.use(function(req, res, next) {
  22. next(createError(404));
  23. });
  24. // error handler
  25. app.use(function(err, req, res, next) {
  26. // set locals, only providing error in development
  27. res.locals.message = err.message;
  28. res.locals.error = req.app.get('env') === 'development' ? err : {};
  29. // render the error page
  30. res.status(err.status || 500);
  31. res.render('error');
  32. });
  33. module.exports = app;