我正在和一位程序员一起开展一个项目,我们遇到了一些阻碍。我们都是使用MEAN堆栈的新手,并且在调试问题时遇到了一些麻烦。我的同事对文件进行了一些更改,现在我无法访问我们的localhost页面。奇怪的是,页面只是没有加载而不是错误,并且下面的消息显示在终端中。
http://localhost:3000/
We are connected
GET / - - ms - -
GET / - - ms - -
GET / - - ms - -
GET / - - ms - -
我试过谷歌搜索消息,但它没有帮助我缩小问题范围。我有一种感觉,因为一切都在他的结束仍然可能我们忘了添加--save到某种类型的npm安装。有没有人知道是否有办法找到未安装到package.json的已安装的依赖项之间的差异?或者,如果有人知道这可能发生的另一个原因,请告诉我!
谢谢!
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 mongoose = require('mongoose');
var session = require('express-session');
var MongoClient = require('mongodb').MongoClient;
var session = require('client-sessions');
// var users = require('./routes/users');
var fs = require('fs');
var app = express();
//set mongo db connection
var db = mongoose.connection;
mongoose.connect('mongodb://localhost:27017/test', function(err, db) {
if(!err) {
console.log("We are connected");
};
});
// Bootstrap models
var models_path = __dirname + '/models'
fs.readdirSync(models_path).forEach(function (file) {
if (file.substr(-3) == '.js') {
require(models_path+'/'+file);
}
});
// 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(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(session({
cookieName: 'session',
secret: 'something',
resave: true,
saveUninitialized: true,
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
}));
// Attach Routes: 'index.js'
require('./routes/index')(app);
app.get('/', function(req, res) {
res.render('index', { title: 'Buddha Bar' })
});
app.use(express.static(path.join(__dirname, 'public')));
//make sesssions available to the router?
app.use(function(req, res, next) {
if (req.session && req.session.user) {
User.findOne({ username: req.session.user.username }, function(err, user) {
if (user) {
req.user = currentUser;
delete req.user.password; // delete the password from the session
req.session.user = currentUser; //refresh the session value
res.locals.user = currentUser;
}
// finishing processing the middleware and run the route
next();
});
} else {
next();
}
});
// Make our db accessible to our router
app.use(function(req, res, next){
req.db = db;
next();
});
// error handlers
// 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 error 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: {}
});
});
module.exports = app;
答案 0 :(得分:0)
正如评论中所建议的,我首先要考虑剥离中间件,直到你有一个最小的工作服务器,然后系统地重新添加。
您的记录器确实输出某些,这让我觉得没有挂中间件(即没有next()
或其他终止呼叫)但可能是请求对象本身,或者至少一些预期的属性被篡改。看看摩根代码,它确实看起来像the dash (-
) is its fallback token,因为它无法获得价值。在你的情况下,看起来摩根不能计算开发模式中除方法和URL之外的任何值。