您好,我正在尝试在我的应用程序中使用 Express EJS 布局。一旦我尝试app.use(expressEjsLayouts)它就会抛出错误。如果没有它,应用程序工作得很好,但我想在我的模板中使用 ExpressEjs-Layouts。请友善,我对编码相当陌生:)我已经浏览了很多帖子,但找不到答案。这是我的 server.js
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require('express')
const app = express()
const passport = require('passport')
const flash = require('express-flash')
const session = require('express-session')
const methodOverride = require('method-override')
const indexRouter = require("./routes/index")
app.use(express.urlencoded({ extended: false }))
app.use(flash())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
const initializePassport = require('./passport-config')
const expressEjsLayouts = require('express-ejs-layouts')
initializePassport(
passport,
email => indexRouter.users.find(user => user.email === email),
id => indexRouter.users.find(user => user.id === id)
)
// Set Template Engine
app.use(expressEjsLayouts) // THIS SEEMS TO BE WHAT MAKES IT CRASH
app.set("layout", "layouts/layout")
app.set('view-engine', 'ejs')
app.set("views", __dirname + "/views")
// Static Files
app.use(express.static("public"))
app.use("/", indexRouter.router)
app.use(methodOverride('_method'))
app.listen(process.env.PORT || 3000)
千巷猫影
当年话下
相关分类