-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (35 loc) · 1.15 KB
/
app.js
File metadata and controls
43 lines (35 loc) · 1.15 KB
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
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const routes = require('./routes/index');
const books = require('./routes/books');
// const usersRouter = require('./routes/users');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/books', books)
// app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function (req, res, next) {
const error = new Error("Could not find on server");
error.status = 404
res.render('page-not-found', {error})
});
// Global error handler
app.use((err, req, res, next) => {
// render the error page
err.status = (err.status || 500);
err.message = (err.message || "Oops there was an error on the server-side");
res.render('error', { err });
}
);
module.exports = app;