shin-neo-lyrical-tokarev/app.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-11-16 02:11:07 -05:00
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 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);
}
}}));
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!"
});
});