我使用Express(Nodejs)创建这个简单的网站,我不知道Web应用程序有什么问题。它不会在视图中呈现联系页面。我使用EJS作为视图引擎。请告诉我我做错了什么。它在浏览器上显示错误500,无法找到任何响应,我不知道为什么它显示,因为一切看起来都很完美,文件在相应的文件夹中。
这是app.js文件(默认文件)
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 nodemailer = require('nodemailer');
var index = require('./routes/index');
var users = require('./routes/users');
var about = require('./routes/about');
var contact = require('./routes/contact');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
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')));
app.use('/', index);
app.use('/users', users);
app.use('/about', about);
app.use('/contact', contact);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(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;
这是我在默认文件夹路由中的contact.js文件。
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('contact', { title: 'contact' });
});
module.exports = router;
这是views文件夹中的contact.ejs文件。
<% incude layout.ejs %>
<div class="Jombotron">
<div class="container">
<div class="row">
<h1>About us</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu consequat neque. Quisque aliquam turpis id metus facilisis dapibus. Nullam a tellus dui.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu consequat neque. Quisque aliquam turpis id metus facilisis dapibus. Nullam a tellus dui.
</p>
</div>
</div>
</div>
<% include footer.ejs %>