我正在尝试将几块哈巴狗转换为EJS,但它不起作用,而且也使我的页面崩溃了。
试图显示我的“注册表单”的“错误消息”,但无法将以下哈巴狗转换为EJS:
myMenu.onSelect = greyOutMenu();
我还试图将下面的哈巴狗转换为EJS的“消息”(使用Flash),说“您现在已登录”:
ul.errors
if errors
each error, i in errors
li.alert.alert-danger #{error.msg}
例如,当我在“注册”页面或“主页”页面上,但又一次努力将哈巴狗转换为EJS时,则说一门课程是“活动的”:
!= messages()
我的App.js类
li(class=(title == 'Signup' ? 'active' : ''))
User.js
// define dependencies
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var ejs = require('ejs');
var expressValidator = require('express-validator');
var multer = require('multer');
var upload = multer({dest: './uploads'});
var flash = require('connect-flash');
var bcrypt = require('bcryptjs');
var mongo = require('mongodb');
var mongoose = require('mongoose');
var db = mongoose.connection;
// const PORT = 3000; // you can change this if this port number is not available
const port = process.env.PORT || 3000;
//requiring the routes
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
//view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// Handle Sessions
app.use(session({
secret: 'secret',
saveUninitialized: true,
resave: true
}));
//passport middleware
app.use(passport.initialize());
app.use(passport.session());
//Express Validator middleware
app.use(expressValidator({
errorFormatter: function(param, msg, value){
var namespace = param.split('.'),
root = namespace.shift(),
formParam = root;
while(namespace.length){
formParam += '[' + namespace.shift() + ']';
}
return {
param : formParam,
msg : msg,
value : value
};
}
}));
//flash middleware
app.use(require('connect-flash')());
app.use(function (req, res, next) {
res.locals.messages = require('express-messages')(req, res);
next();
});
app.get('*', function(req, res, next){
res.locals.user = req.user || null;
next();
});
app.use('/', routes);
app.use('/users', users);
//catch 404 and forward to error handler
app.use(function(req, res, next){
var err = new Error('Not Found');
err.status = 404;
next(err);
});
//development error handler
//will print stacktrace
if (app.get('env') === 'development'){
app.use(function(err, req, res, next){
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
//production erro handler
//no stacktraces leaked to user
app.use(function(err, req, res, next){
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
app.listen(port, () =>{
console.log(`Server is up on port ${port}`);
});
module.exports = app;
Git回购:https://github.com/johnnymunster/WebDev-Project Heroku Url:https://glacial-castle-40173.herokuapp.com/
预先感谢 约翰尼