38 lines
922 B
JavaScript
38 lines
922 B
JavaScript
const express = require('express')
|
|
const path = require('path')
|
|
const indexRouter = require('./routes/index')
|
|
const { MAINTENANCE, BASE, DEV } = require('./config')
|
|
|
|
const app = express()
|
|
|
|
// view engine setup
|
|
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')))
|
|
|
|
app.locals.base = BASE
|
|
|
|
if (MAINTENANCE) {
|
|
app.get('/', (req, res) => res.render('maintenance'))
|
|
app.use('/test', indexRouter)
|
|
} else {
|
|
app.use('/', indexRouter)
|
|
}
|
|
|
|
// catch 404
|
|
app.use( (req, res) => res.render('404') )
|
|
|
|
// error handler
|
|
app.use(function(err, req, res, next) {
|
|
// set locals, only providing error in development
|
|
res.locals.message = DEV ? err.message : ''
|
|
res.locals.error = DEV ? err : {}
|
|
|
|
// render the error page
|
|
res.status(err.status || 500)
|
|
res.render('error')
|
|
})
|
|
|
|
module.exports = app
|