Node JS, не грузится страница, не отображаются стили
const path = require('path')
const express = require('express')
const exphbs = require('express-handlebars')
const mainRoutes = require('./routes/main')
const blogRoutes = require('./routes/blog')
const feedbackRoutes = require('./routes/feedback')
const messageRoutes = require('./routes/message')
const app = express()
const hbs = exphbs.create({
defaultLayout: 'main',
extname: 'hbs'
})
app.engine('hbs', hbs.engine)
app.set('view engine', 'hbs')
app.set('views', 'pages')
app.use(express.static(path.join(__dirname, 'public')))
app.use(express.urlencoded({extended: true}))
app.use('/', mainRoutes)
app.use('/blog', blogRoutes)
app.use('/feedback', feedbackRoutes)
app.use('/message', messageRoutes)
const PORT = process.env.PORT || 3000
app.listen(3000, () => {
console.log(`Server is running on port ${PORT}`)
})
const {Router} = require('express')
const Publication = require('../models/publication')
const router = Router()
router.get('/', async (req, res) => {
const publications = await Publication.getAll()
res.render('blog', {
title: 'Блог',
isBlog: true,
publications
})
//const np = new Publication('Любовь к себе', './img/post_1.jpg', 'Тест на возраст. Помните этот мультик? Конечно, это Чертёнок № 13. До сих пор ржу с его юмора, серию про любовь обожаю, рекомендую всем. Чего только стоит один учитель всех чертят, который вечно учил их плохому.').save()
})
router.get('/:id', async (req, res) => {
const publication = await Publication.getById(req.params.id)
res.render('openPost', {
title: `${publication.title}`,
publication
})
})
module.exports = router
{{#if publications.length}}
{{#each publications}}
<div class="blog">
<div class="blog__item">
<p class="blog__item__title">{{title}}</p>
<div class="blog__content">
<img class="blog__content__img" src="{{img}}" alt="{{title}}">
<p class="blog__content__text">{{text}}</p>
</div>
</div>
<a href="/blog/{{id}}" target="_blank">Читать</a>
</div>
{{/each}}
{{else}}
<p class="blog__title">Постов нет</p>
{{/if}}
<div class="blog">
<div class="blog__item">
<p class="blog__item__title">{{publication.title}}</p>
<div class="blog__content">
<img class="blog__content__img" src="{{publication.img}}" alt="{{publication.title}}">
<p class="blog__content__text">{{publication.text}}</p>
</div>
</div>
</div>
Всем привет! Пишу сайт на ноде по курсу. Использую экспресс и хэндлбарс. Вроде, все сделал также, но не грузится страница. При подгрузке зависает, а когда останавливаю загрузку, данные отображаются, но при этом не грузит стили, и в консоли возникает ошибка
(node:7412) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'title' of undefined
at C:\Users\kill0\Desktop\psyholog\routes\blog.js:19:31
(Use node --trace-warnings ... to show where the warning was created)
(node:7412) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the
CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7412) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.