Initial Commit
This commit is contained in:
33
app.js
Normal file
33
app.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const express = require('express')
|
||||
const handlebars = require('express-handlebars')
|
||||
const path = require('path')
|
||||
const routes = require('./routes/index')
|
||||
|
||||
const port = 3000
|
||||
|
||||
const app = express()
|
||||
app.engine('.hbs', handlebars({defaultLayout: 'layout', extname: '.hbs'}))
|
||||
|
||||
app.set('views', path.join(__dirname, 'views'))
|
||||
app.set('view engine', '.hbs')
|
||||
|
||||
app.use(express.static(path.join(__dirname, 'public')))
|
||||
app.use('/', routes)
|
||||
|
||||
app.use((request, response, next) => {
|
||||
const err = new Error('Not Found')
|
||||
err.status = 404
|
||||
next(err)
|
||||
})
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
res.locals.message = err.message
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
||||
|
||||
res.status(err.status || 500)
|
||||
res.render('error')
|
||||
})
|
||||
|
||||
app.listen(port, () => console.log(`Listening on port : ${port}!`))
|
||||
|
||||
module.exports = app
|
||||
Reference in New Issue
Block a user