У меня проблема, когда я добавляю <%- include('../partials/header'); %>
к другим моим файлам e js
<%- include('../partials/header'); %>
<% posts.forEach((post) => { %>
<img src="<%= post.postimage %>" alt="" />
<% }); %>
, и когда я go к маршруту, я получаю эту ошибку в браузере HTTP ERROR 500
и эта ошибка в моей консоли GET /posts 500 3.827 ms - 0
это мое приложение. js
const createError = require("http-errors");
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const mongoose = require("mongoose");
const passport = require("passport");
const LocalStrategy = require("passport-local");
const bodyParser = require("body-parser");
const partials = require("express-partials");
//models
const User = require("./models/user");
//routs
const index = require("./routes/index");
const posts = require("./routes/posts");
const comments = require("./routes/comments");
mongoose.Promise = global.Promise;
const databadeURL = "mongodb://127.0.0.1:27017/instagram-clone";
mongoose
.connect(databadeURL, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log("Database connected");
})
.catch((err) => {
console.log(err);
});
const app = express();
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(partials());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(logger("dev"));
app.use("/uploads", express.static("uploads"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
app.use(
require("express-session")({
secret: "Instagram-clone",
resave: false,
saveUninitialized: false,
})
);
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
app.use("/", index);
app.use("/posts", posts);
app.use("/posts/:post_id/comments", comments);
// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
});
// error handler
app.use((err, req, res, next) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
// render the error page
res.status(err.status || 500);
res.render("error");
});
module.exports = app;
- версии
Node JS: 12.16.2 e js: 3.1.2 express: ~ 4.16.1
Это моя проблема Спасибо за вашу помощь :)