2024-06-22 14:08:05 -04:00
|
|
|
const createError = require('http-errors')
|
|
|
|
const express = require('express')
|
|
|
|
const path = require('path')
|
|
|
|
const cookieParser = require('cookie-parser')
|
|
|
|
const logger = require('morgan')
|
2024-06-22 08:09:40 -04:00
|
|
|
|
2024-06-22 14:08:05 -04:00
|
|
|
const indexRouter = require('./routes/index')
|
2024-06-22 08:09:40 -04:00
|
|
|
|
2024-06-22 14:08:05 -04:00
|
|
|
const app = express()
|
2024-06-22 08:09:40 -04:00
|
|
|
|
|
|
|
// view engine setup
|
2024-06-22 14:08:05 -04:00
|
|
|
app.set('views', path.join(__dirname, 'views'))
|
|
|
|
app.set('view engine', 'ejs')
|
2024-06-22 08:09:40 -04:00
|
|
|
|
2024-06-22 14:08:05 -04:00
|
|
|
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')))
|
2024-06-22 08:09:40 -04:00
|
|
|
|
2024-06-22 14:08:05 -04:00
|
|
|
app.use('/', indexRouter)
|
2024-06-22 08:09:40 -04:00
|
|
|
|
|
|
|
// catch 404 and forward to error handler
|
2024-06-22 14:08:05 -04:00
|
|
|
app.use(function (req, res, next) {
|
|
|
|
next(createError(404))
|
|
|
|
})
|
2024-06-22 08:09:40 -04:00
|
|
|
|
|
|
|
// error handler
|
2024-06-22 14:08:05 -04:00
|
|
|
app.use((err, req, res, next) => {
|
2024-06-22 08:09:40 -04:00
|
|
|
// set locals, only providing error in development
|
2024-06-22 14:08:05 -04:00
|
|
|
res.locals.message = err.message
|
|
|
|
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
2024-06-22 08:09:40 -04:00
|
|
|
|
|
|
|
// render the error page
|
2024-06-22 14:08:05 -04:00
|
|
|
res.status(err.status || 500)
|
|
|
|
res.render('error')
|
|
|
|
})
|
2024-06-22 08:09:40 -04:00
|
|
|
|
2024-06-22 14:08:05 -04:00
|
|
|
module.exports = app
|