fugadalcontrollo/app.js

39 lines
922 B
JavaScript
Raw Permalink Normal View History

2018-08-26 23:41:51 +02:00
const express = require('express')
const path = require('path')
const indexRouter = require('./routes/index')
const { MAINTENANCE, BASE, DEV } = require('./config')
2018-07-21 00:55:00 +02:00
2018-08-26 23:41:51 +02:00
const app = express()
2018-07-21 00:55:00 +02:00
// view engine setup
2018-08-26 23:41:51 +02:00
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
app.use(express.urlencoded({ extended: false }))
app.use(express.static(path.join(__dirname, 'public')))
2018-07-21 00:55:00 +02:00
2018-08-26 23:41:51 +02:00
app.locals.base = BASE
2018-07-21 00:55:00 +02:00
2018-08-26 23:41:51 +02:00
if (MAINTENANCE) {
app.get('/', (req, res) => res.render('maintenance'))
app.use('/test', indexRouter)
} else {
app.use('/', indexRouter)
}
2018-07-21 00:55:00 +02:00
2018-08-26 23:41:51 +02:00
// catch 404
app.use( (req, res) => res.render('404') )
2018-07-21 00:55:00 +02:00
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
2018-08-26 23:41:51 +02:00
res.locals.message = DEV ? err.message : ''
res.locals.error = DEV ? err : {}
2018-07-21 00:55:00 +02:00
// render the error page
2018-08-26 23:41:51 +02:00
res.status(err.status || 500)
res.render('error')
})
2018-07-21 00:55:00 +02:00
2018-08-26 23:41:51 +02:00
module.exports = app