shin-neo-lyrical-tokarev/index.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-11-16 02:11:07 -05:00
const express = require('express')
2024-12-04 01:46:31 -05:00
const webserver = express()
2024-11-16 02:11:07 -05:00
const port = 3003
const serveIndex = require('./src/utils/serve_index')
const {engine} = require('express-handlebars')
const indexRouter = require('./src/router/indexRouter')
2024-11-16 16:53:05 -05:00
const { handlebars } = require('hbs')
2024-12-04 22:56:01 -05:00
const bodyParser = require('body-parser')
2024-11-16 02:11:07 -05:00
const publicPath = "/public"
const inUrlPath = "public"
2024-12-04 01:46:31 -05:00
webserver.engine('.hbs', engine({extname: '.hbs', helpers: {
2024-11-16 02:11:07 -05:00
ifDivisibleBy: function (index, divisor, options) {
2024-12-04 22:56:01 -05:00
if ((index+1) % divisor === 0) {
2024-11-16 02:11:07 -05:00
return options.fn(this);
}
},
ifEquals: function(arg1, arg2, options) {
return (arg1 == arg2) ? options.fn(this) : options.inverse(this);
2024-11-16 16:53:05 -05:00
},
raw: function(string){
return (new handlebars.SafeString(string))
2024-11-16 02:11:07 -05:00
}
}}));
2024-12-04 01:46:31 -05:00
webserver.set('view engine', '.hbs');
2024-11-16 02:11:07 -05:00
2024-12-04 01:46:31 -05:00
webserver.use(publicPath, express.static(inUrlPath), serveIndex(inUrlPath, {
2024-11-16 02:11:07 -05:00
}))
2024-12-04 22:56:01 -05:00
webserver.use(bodyParser.urlencoded({extend: false}));
webserver.use(bodyParser.json());
2024-11-16 02:11:07 -05:00
2024-12-04 01:46:31 -05:00
webserver.listen(port, () => {
2024-11-16 02:11:07 -05:00
console.log(`Listening on port ${port}`)
})
2024-12-04 01:46:31 -05:00
webserver.use('/', indexRouter)
2024-11-16 02:11:07 -05:00
2024-12-04 01:46:31 -05:00
webserver.use((err, _req, res, next) =>{
2024-11-16 02:11:07 -05:00
if (err){
console.error(err)
res.send("It was terrible. Check the logs for more details.")
}
else next()
})
2024-12-04 01:46:31 -05:00
webserver.use((_req, res, _next) => {
2024-11-16 02:11:07 -05:00
res.status(404).render('404', {
stylesheet: '/public/styles/404/index.css',
title: "404!"
});
});