50 lines
1.2 KiB
JavaScript
50 lines
1.2 KiB
JavaScript
const express = require('express')
|
|
const app = express()
|
|
const port = 3003
|
|
const serveIndex = require('./src/utils/serve_index')
|
|
const {engine} = require('express-handlebars')
|
|
const indexRouter = require('./src/router/indexRouter')
|
|
const { handlebars } = require('hbs')
|
|
|
|
const publicPath = "/public"
|
|
const inUrlPath = "public"
|
|
|
|
app.engine('.hbs', engine({extname: '.hbs', helpers: {
|
|
ifDivisibleBy: function (index, divisor, options) {
|
|
if (index % divisor === 0) {
|
|
return options.fn(this);
|
|
}
|
|
},
|
|
ifEquals: function(arg1, arg2, options) {
|
|
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
|
|
},
|
|
raw: function(string){
|
|
return (new handlebars.SafeString(string))
|
|
}
|
|
}}));
|
|
app.set('view engine', '.hbs');
|
|
|
|
app.use(publicPath, express.static(inUrlPath), serveIndex(inUrlPath, {
|
|
}))
|
|
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Listening on port ${port}`)
|
|
})
|
|
|
|
app.use('/', indexRouter)
|
|
|
|
app.use((err, _req, res, next) =>{
|
|
if (err){
|
|
console.error(err)
|
|
res.send("It was terrible. Check the logs for more details.")
|
|
}
|
|
else next()
|
|
})
|
|
|
|
app.use((_req, res, _next) => {
|
|
res.status(404).render('404', {
|
|
stylesheet: '/public/styles/404/index.css',
|
|
title: "404!"
|
|
});
|
|
}); |